I came across a hadith in Sahih al-Bukhari; it is a rather long hadith which tells the story of Umar giving a sermon when his death was close. Please read the hadith before proceeding. I excerpt the most salient portions below:
(O people!) I have been informed that a speaker amongst you says, 'By Allah, if 'Umar should die, I will give the pledge of allegiance to such-and-such person.' one should not deceive oneself by saying that the pledge of allegiance given to Abu bakr was given suddenly and it was successful. No doubt, it was like that, but Allah saved (the people) from its evil, and there is none among you who has the qualities of Abu bakr. Remember that whoever gives the pledge of allegiance to anybody among you without consulting the other Muslims, neither that person, nor the person to whom the pledge of allegiance was given, are to be supported, lest they both should be killed. ...
(some disagreement about who is to be caliph follows)
And then one of the Ansar said ... O Quraish. There should be one ruler from us and one from you.' Then there was a hue and cry among the gathering and their voices rose so that I was afraid there might be great disagreement, so I said, 'O Abu bakr! Hold your hand out.' He held his hand out and I pledged allegiance to him, and then all the emigrants gave the Pledge of allegiance and so did the Ansar afterwards. And so we became victorious over Sa'd bin Ubada (whom Al-Ansar wanted to make a ruler). ... Umar added, "By Allah, apart from the great tragedy that had happened to us (i.e. the death of the Prophet), there was no greater problem than the allegiance pledged to Abu bakr because we were afraid that if we left the people, they might give the Pledge of allegiance after us to one of their men, in which case we would have given them our consent for something against our real wish, or would have opposed them and caused great trouble. So if any person gives the Pledge of allegiance to somebody (to become a Caliph) without consulting the other Muslims, then the one he has selected should not be granted allegiance, lest both of them should be killed."
(Sahih al-Bukhari, Book 86, Hadith 6830)
Now my question is about this command of Umar:
"If any person gives the Pledge of allegiance to somebody (to become a Caliph) without consulting the other Muslims, then the one he has selected should not be granted allegiance, lest both of them should be killed."
Given that 'Umar himself did this, my question is as follows:
Is this statement a rule of Shari`ah (religious law)? If so, was `Umar an exception to the rule? If not, did `Umar has invented it for the people coming after him?