A residency permit can but not necessarily equal your legal residence. Jurisdictions can issue residence permits even without you needing to register your address or having a place of residence for yourself in the country.
Tax residency is indeed a totally different matter.
Interestingly, some countries allow people to live full-time in their jurisdiction without considering them tax residents.
Quite often, when there is a need to make it crystal︋ clear, tax treaties will help to do that (UAE has DTT-s with ~130 countries)
For example:
Where by reason an individual is a resident of both Contracting States, then his︌ status shall be determined as follows:
a) he shall be deemed to be a resident︍ only of the Contracting State in which he has a permanent home available to him;︎ if he has a permanent home available to him in both Contracting States, he shall️ be deemed to be a resident only of the Contracting State with which his personal and economic relations are closer (centre of vital interests);
b) if the Contracting State in which he has his centre of vital interests cannot be determined, or if he has a permanent home available to him in neither Contracting State, he shall be deemed to be a resident only of the Contracting State in which he has an habitual abode;
c) if he has an habitual abode in both Contracting States or in neither of them, he shall be deemed to be a resident only of the Contracting State of︀ which he is a national;
d) if he is a national of both Contracting States︁ or of neither of them, the competent authorities of the Contracting States shall settle the︂ question by mutual agreement.