The is no official rule for how long you will be given on re-entry to the US after 5 months in Mexico.
However US Customs and Border Patrol do use a rule-of-thumb that you should be outside of the US for longer than you are in the US. So after a stay of 6 months, followed by being outside of the US for 5 months, that rule of thumb would mean you would ...
No, you don’t have to leave the country. The UK government travel advice for Turkey states:
If you plan to stay in Turkey longer than 90 days, you must apply for a residence permit before the 90 days ends or apply for a longer-stay visa before you travel
So as long as you apply for it before your visa expires you can stay in the country.