This saying is used to allude that one has lost its place or even a chance. Like many sayings, this expression has its origin in a story that happened centuries ago.
It is said that during the kingdom of Henry IV of Trastamara, Sir Alonso from Fonseca held the archbishopric of Seville and his nephew was named Archbishop of Compostela. At that time, in Galicia there were numerous revolts and for this reason Sir Alonso decided to go to Compostela for some time to facilitate the work of his nephew.
So this latter was required to occupy the place of Seville during the absence of his uncle.
On his return, Sir Alonso found his nephew did not want to leave Sevilla and King Henry himself and the pope had to solve the problem. When at last the young man went to Compostela, he had to serve five years in prison for other crimes. However, this did not prevent his rising to the highest ecclesiastical offices and his own son to inherit the post of archbishop.