401(k) penalties when leaving US

I understand early withdrawal from 401(k) have tax consequences that are income tax + 10 % early withdrawal penalty.

 

What is the intention / consequence of this when leaving the US?

 

I am German and assuming I am deciding to leave the US in a few years, then will I have to pay penalties? Are there exceptions or other ways to avoid this? Should I keep the 401(k) and is that even possible? I do not understand of intention of penalties when there is no other choice than dissolving the account?