I've heard that you lose fat in the areas it was last gained. Similarly, the last place you'll lose it is the area you first put on the weight. What is the reason behind this mechanism?
It is both very accurate, and very inaccurate.
When you gain fat, you gain fat in all the fat repositories. On the same coin, when you lose fat, you lose it in all the same places at once.
Important: You can't pick and choose where to gain/lose fat.
The reason why it seems like you gain it in certain areas more than others (like belly and butt), is because these places have the largest fat storage capacity. But equally, this is where you lose more as well, when you lose fat.