Great question! Long story short, it almost always makes sense to invest up the company match, even for temporary U.S. residents.
Here's an article that discusses some of the pros and cons:
https://www.magnifymoney.com/blog/retirement/should-foreign-nationals-contribute-to-401k/And you're right, in your colleague's situation it is prudent to invest enough to get the match. Let's assume the following:
-Your colleague only stays 2 years.
-They invest 3%, and for simplicity we'll say that 3% equals a total of $10,000 after 2 years.
-They would have $4,000 of company match vested after 2 years.
-We'll assume the market stays flat, so there is a total of $14,000 vested in the account.
-If they withdraw that $14,000 with a 10% penalty, they'd have $12,600 left even though they only contributed $10,000.
So with the assumptions above, your colleague would receive $2,600 of funds because of the company match. If they stay longer than 2 years, that benefit increases.
They could also avoid the 10% penalty if they keep their 401k open even after they move back to Germany and wait to withdraw it until they are 59 1/2 years old. That would be an extra administrative hassle, but it could be worth it if the balance is large enough.
The last thing I'll mention is that if your colleague's marginal tax rate is greater than 10%, it likely makes sense for them to contribute as much as they can, up to the max of $19,000 per year. Saving 15%+ on taxes now and paying a 10% penalty later is not a bad prospect.