Yes, a borrower can switch from self-employed to W2 job and get qualified for a mortgage. How long the borrower will need to be at the new W2 job will depend upon the type of W2 income they get (salaried vs hourly vs commission).
Switching a job or employer is not a dead end to your mortgage. The main concern will be the type of income that you currently make vs. how you will be paid in the future.