The juristic position is settled and it is modest. A man's prayer is valid with his head uncovered. Covering it is treated as recommended, as a matter of adab, of good manners before God, on the reasoning that one would not appear bareheaded before a person of consequence in societies where a covered head was the norm. Some jurists have described praying bareheaded without reason as disliked rather than forbidden, and that is the strongest position ordinarily taken.
That is precisely why the practice varies so widely without becoming a dispute. Where a legal obligation exists, difference in practice produces argument; where a recommendation exists, difference produces regional custom, and the Muslim world has a great deal of it.
The contrast with women's covering is instructive and often misunderstood. The requirement of covering in prayer is stated differently for women in the classical discussions and is not the same question as this one, so the cap is not a male counterpart to the headscarf and is not treated as one within the tradition.
Its political charge is entirely modern and entirely local. In some countries it reads as ordinary dress and in others as a statement, and the same cap can be a national costume, a religious observance, an ethnic marker or simply what a man's father wore, depending on where he is standing.