The past and past perfect continuous are used to refer to an event which is closely related to a second and usually shorter event:
The Past continuous can be used to show an action which was happening in the past. It is important to remember that the Past continuous is usually used to show an action which was happening when another action, which is usually shorter, happened at the same time, stopped the continuous action or started after the continuous action.
"Before he became a teacher of Urdu" may not be a shorter event than living in Pakistan for 3 years, and the sentence does not suggest that the event was what stopped John spending time in Pakistan. Thus the conditional tense is not required.
If those conditions were met, the sentence might read as follows:
John had been spending 3 years in Pakistan when he submitted an application to become a teacher of Urdu.
In this case, submitting an application is a discrete task that is shorter in time and interrupts his time in Pakistan.
The difference is subtle. If you used the past perfect continuous with your example sentence, readers and hearers would understand you. However, they might sense something is off because the emphasis on the continuous action isn't necessary to understand how he became a teacher.