It is not only legal, but limiting the contributions of HCEs is a requirement of the law: https://www.fool.com/retirement/plans/401k/highly-compensated-employee/
In short, they didn't want this to become a plan just for the top/richest employees to be able to tax defer their income. Therefore, there must be enough of the non-HCEs participating in the plan ...
If you don't have the money already to make an investment, don't borrow it! Don't borrow it from your retirement funds, don't borrow it from the equity in your house, don't borrow it from friends or family. Why? Well, what are you going to do if the "investment opportunity" doesn't pan out the way you think it will and you end up losing all or a ...
Let's look at it from a pros/cons perspective:
No required payback
~50% tax and penalties on withdrawal.
Permanent loss of value if you don't replenish it.
Home Equity Loan Pros:
How are you going to pay the loan back if the investment is a bust?
Another option (depending on your 401(k) plan) would ...