Muhammad (PBUH) originally lived in Mecca, but after spreading the word of Allah (SWT) to the people of Mecca, who - at the time believed in multiple gods - he and his followers were persecuted, and so they left for Medina. Some years later, Muhammad (PBUH) returned to Mecca and was respected by those who had previously persecuted him, and he and his followers were allowed to practice their beliefs without persecution.