The simplest explanation is often the closest to the truth. Perhaps John McCain chose Sarah Palin purposely because she is unqualified to be president. Why would he do that? I think it is the only way to ensure he would get to serve his entire term if he wins the election. If Romney were the Vice President, do you think the GOP establishment would let a 72+ year old, confused, 4 time cancer patient serve out his entire term?
John McCain may seem confused speaking in public, but he has shown remarkable skill in politics (and in life) to reach the positions he has. Others have noted how cynical a person he is at heart, almost pure Machiavellian. So we should expect his VP choice to reflect a purely rational decision that maximizes the power it brings to McCain.
To see this, consider the predicament McCain is in. The GOP establishment does not trust him because he will pull the maverick thing against the GOP on occasion to raise his personal profile. To them, McCain is definitely not a sure bet to take any particular action that they prefer. Accordingly, the powers that be have pushed Mitt Romney even though he is probably unelectable. The strongest recent example of this is the rumor that Karl Rove was pushing furiously for Romney. If you are Karl Rove, how you could get Romney with his electability problem in the Presidency? There is only one way - through the VP office and a resigning or deceased President.
Hence, if Romney (or either of the female Senators Hutchinson or Snowe) were VP, John McCain would spend his entire presidency looking over his shoulder because at any time the GOP might spin up the Wurlitzer and try to convince the country he is not physically fit to be President. This could be because of the cancer or the dementia issue. If you were John McCain would you trust Karl Rove to not actively try to replace you? Before McCain is even sworn in the rumors will swirl in the MSM that his cancer is more serious that thought before and that he was secretly tested as having early Alzheimer's. Let this build for a while and combine it McCain speaking gaffes (which will undoubtedly occur)and you have a presidential crisis that is solved by elevating the VP to President.
Given this situation, the rational thing for McCain to do would be to pick a VP who would not be acceptable to the GOP establishment. The logical choice for him would be Joe Lieberman because there is no way McCain would be pushed out by the GOP to install a former democrat. Lieberman as VP plays up the bi-partisan issue and the two actually would work together in the oval office because they get along well and see things similarly. This explains why, from media reports, McCain's first choice was Lieberman.
If the powers that be tell you that you can't pick Lieberman, who would you choose next? If the best bet is to take a woman to try and pick up Hillary voters, choosing a qualified female GOP senator will put him in the same forced resignation situation. So what would allow McCain to serve as President without fear of GOP undermining him? Pick someone who the GOP would be unwilling to elevate to President.
Hence, I believe the Palin pick is rational. It is exactly what I would expect from John Sidney McCain, a man who only looks out for himself. Screw the country, if he can get elected with Palin as VP, he can be sure he will get to serve his entire term as President. Maybe he takes a hit in electability, but he would rather take a lower chance of being elected with a guaranteed term than take a higher probability of winning with a VP the GOP establishment would openly prefer was the President. Doing the former, he remains the "man" that everyone looks to, while with the latter, he is the obstacle in the way of standard GOP operations.