Anyone pledges allegiance to a ruler, giving him the grasp of his hand and sincerity of his heart, he should obey him to the best of his capacity. If another man comes forward disputing his authority, then you should behead the latter
Abdullāh ibn ‘Amr (may Allah be pleased with him) reported: We were on a journey with the Messenger of Allah (may Allah's peace and blessings be upon him) and we halted at some place to rest. Some of us began to mend their tents; others began to compete with one another…

