Missionaries end their role for a variety of reasons. Some are planned and some are not.
The task is finished. For example, if your goal was to plant a church that is led by godly nationals and is reproducing itself, or to establish a ministry such as a Theological Education by Extension system, and that has occurred, you’ve completed your job and are free to move on.
The calling shifts or evolves. Often God moves missionaries into several different ministries. For example, one missionary family went to Western Europe to church plant among Arab Muslims. After arriving, they encountered an increasing number of Berbers from North Africa, the original inhabitants of that region with a different language and culture than Arabs. Their ministry to Berbers flourished, and they eventually decided to move to North Africa to pioneer church plant among Berbers. The man had strong linguistic abilities and spent a few years producing a language learning course for others entering ministry among Berbers. Eventually they were expelled from the country and returned to Western Europe to church plant among Berbers.
The method of entry ends. Particularly in creative access countries, your host country may choose to expel you, or your job may end. With no legal way to remain in the country, you must leave.
Family circumstances require a change. Missionaries often return home for aging parents, or children with medical or educational needs that cannot be met overseas.
The career ends. For health or aging reasons, it’s time to retire.