Again they don't allow 100% 401k loan but if they did and I could set a short term loan length, I would do the following:
Take out a manageable sized 401k loan. Invest it in a taxable account and keep it invested long term. Of course it would not go under a mattress, that would defeat the purpose.
Pay back the 401k loan plus 100% interest into the 401k.
In effect this would just be a way to put more investment into 401k instead of taxable investment if there is no more tax deferred space available to invest.
Note: I revised my previous post because I double-counted the taxes paid in one scenario.
So you want to take money out of a tax-deferred account via a loan, invest those dollars in a taxable account, and then pay tax on the income required to pay the loan back, all under the assumption that it will put more money in your tax deferred account and you'll be in a better net financial position? That can only make sense if there is zero cost to the 401k loan.
Let's revisit the prior scenarios. Assume: $100K 401k balance, lump sum loan repayment after 1 year (just to make the math easy).
Scenario A. Take out $10K loan. $90K remaining grows to $96,300. Earn $25K, pay $5K in taxes, and use remaining $20K to pay back loan. $116,300 in assets in 401k after year 1. $10,700 in taxable account. $127,000 total assets.
Scenario B. No loan. $100K grows to $107,000. $20,000 in taxable savings on your $25K in earnings. $127,000 total assets.
I'll concede that you achieved your goal of putting more money into your 401k. Except you need to also cover the loan fees in scenario A, so you'll be slightly behind in dollars. Assuming you can invest in the same things both inside and outside of your 401k, you'd have to make assumptions on future tax liabilities to say scenario A is ultimately better.
The point of my example is not to do this in practice since the option does not exist, it's that people should not be overly focused on or fearful of the 401k loan rate since you are paying yourself back.
The loan rate is absolutely relevant. If I can borrow money to buy a car from the bank at 3% or my 401k at 5% what one is better? The 3% bank loan every day of the week. Bank loan or 401k loan, you have to use after tax dollars to pay the interest. You want to pay the least amount of interest. Bank loan at 6% or 401k loan at 5%? The bank loan at 6%, assuming 7% market returns on your 401k.
You are not "paying yourself back" when you take out a 401k loan. That is a common misconception. You are taking out a loan. 401k is shifting its assests. They are two separate, independent things. If your 401k could loan me money, I wouldn't be able to say that I'm paying myself back, but I'd still be using my after-tax dollars to repay the loan. There is nothing magical about a 401k loan, other than the fact it doesn't care about your credit score when you take it out.