You can read the May 1945 Target Committee meeting minutes — they are very illuminating as to the selection process. The long and short of it is that they wanted cities that had not already been extensively bombed, that would (in their assessment) be good targets for the kind of damage the atomic bombs did, and had some sort of military or industrial relevance.
It is worth noting that Hiroshima and Nagasaki were not the initial choices for the bombs. The initial list was, in order of priority, Kyoto, Hiroshima, Kokura, and Niigata.
The target the scientists and the military desired most of all was Kyoto. This was removed from the list by Henry Stimson, the Secretary of War, with the agreement of President Harry Truman, who bought Stimson's argument that Kyoto was a "civilian" target whereas Hiroshima was a "military" target. (This was, I argue in a forthcoming paper, the only major pre-bombing decision that Truman made regarding the atomic bomb. Truman made two important decisions about the atomic bombs: 1. Hiroshima and not Kyoto, and 2. to halt atomic bombing on August 10th. Of note is that the decision as to whether to use the bomb is not one of those decisions — Truman did not really make that decision, he just assumed it would be used like almost everyone else did. The idea that it was an agonizing decision is not true.)
Removing Kyoto from the list not only made Hiroshima go into the primary slot, but it also meant that in order to have enough backup targets, they had to add another city to the list. (Niigata was effectively removed from consideration when Kyoto was removed — it was too far away from Hiroshima and Kokura to be a realistic backup.) This meant that Nagasaki was added to the list, just before the list was finalized.
The second bombing run was meant to destroy Kokura, but clouds and/or smoke (it isn't clear which) obscured the target. So the bomber went to the secondary target, Nagasaki.
For a lot more detail on the Kyoto decision, you can read my earlier blog post on the matter here (I have since revised this into a quite long article which is making its way through the editorial process). On Kokura, see here. On Niigata, see here. On the Nagasaki raid, and the many mishaps that occurred during the mission, see here.
What was significant about these cities vs the capital or military targets?