Generally speaking: yes, you can be sued if you move out of the home, but no, you do not go to jail for it.
So, if a person simply up and leaves a home on which they owe a mortgage, the mortgage lender can sue the person to foreclose the property. If the property does not sell for enough at the foreclosure sale to pay the mortgage loan plus costs in full, the mortgage lender can usually go after the person for the difference left owing, called the "deficiency balance." This varies from state to state, but that's how it usually spins out. Some states do not allow the mortgage lender to pursue the deficiency balance, or only allows the lender to pursue it in certain circumstances. In my jurisdiction, lenders are always allowed to pursue it.
Generally it is wise for one who just leaves a home to notify the lender in writing, and keep a copy, that he or she is leaving so the lender can change the locks and take other actions to protect the property (winterize it, etc). If a person just leaves and doesn't notify the lender, the lender may have additional claims against the person for negligently or willfully allowing the house to get damaged or fall into serious disrepair.
If one files bankruptcy, the lender still often has to foreclose the property to get the person's name off the deed, so frequently a bankruptcy is followed by a foreclosure. But, the big difference is that the deficiency balance is discharged by the bankruptcy, so the lender cannot ever come after the person for any money (unless, like I mentioned earlier, the person willfully damaged the home, etc.).
Many people let the lender foreclose first, and if the lender pursues a deficiency balance, then they file bankruptcy and discharge it. If the lender never pursues the deficiency, then they do not have to file bankruptcy.
I hope this helps and a positive feedback is always appreciated if this was useful to you.
LEGAL NOTICE: I am only licensed to practice law in certain state(s) and I cannot give legal advice to someone who does not reside in a state in which I am licensed, nor shall anything I say in the above answer or elsewhere on this site be deemed legal advice, even to someone who resides in a state in which I am licensed. Fees I receive for answering questions are paid for information, not for legal advice. This forum is designed to provide general information only, and information herein is not warranted to be correct or applicable in any way since laws may have been misinterpreted herein, since laws change from time to time, and since the impact of those laws on any particular situation varies. The information presented in this site shall not be construed to be formal legal advice nor the formation of an attorney-client relationship. Persons accessing this response are encouraged to seek independent legal counsel in their jurisdiction for guidance regarding their individual circumstances. Do not take any action or inaction based on information presented herein since it is informational and may not be accurate or applicable to you; it merely attempts to give you a basis of knowledge to help you formulate questions to ask a legal or other professional in a face-to-face meeting in your jurisdiction. Joseph Ross does not hold himself out to be a specialist or expert in any area, regardless of assertions made by any third party, and any implication of being an expert or specialist herein is made in error. I hope the information presented above is useful to you. Answer above is (c) Joseph Ross. All rights reserved.