When thinking about nukes, remember that the whole point is to not fire them - their value lies in deterrence, and in everyone knowing the horrible things that would happen if they were fired (this is less the case with tactical nuclear weapons, but Iran doesn't have those). So if you're using them for deterrence - especially in the case when you're up against a much stronger enemy - you target them (and announce this) in such a way as to cause the greatest damage for the greatest number of parties.
Let's say Iran had a nuke, and was feeling so threatened that it had to launch its nuke. If it takes out Jerusalem, it destroys a significant pilgrimage location for Islam, as well as the capital of the (local) great enemy. The US then comes and levels most of the country, and the Israelis likely drop a nuke on Tehran. There's also the pretty good possibility that the Israelis would be successful in shooting down the missile, but would still launch an overwhelming military response. Israel is now in bad shape, Iran is gone, and the rest of the local Arab countries are pretty unhappy, but still alive and kicking.
If they launch on Mecca, there's a much greater change of the thing detonating where it's supposed to. They also destroy a very significant Islamic pilgrimage site. The rest of the Arab world then converges on attacking Iran (with American blessing), as well as Israel (the Sunni states would use the logic that those evil Shiites must have conspired with the Israelis to do this). This results in the US now getting involved militarily to protect Israel, and now you've got a pretty serious war going on in the Middle East, disturbingly close to both India and Russia.
Of those two, the second causes much more hell - which is what they're going for. The second also has the benefit of making the Islamic states much more interested in dealing with their threats, and possibly getting the US to (covertly) be more accommodating.