Borrowing more money than you need to purchase the home is not illegal. What is illegal is borrowing more than appraisal.
Why would that be illegal? I do know for sure that someone loaning you more than appraisal is foolish, they won't have any way to get their money back if you stop making payments. In my example I mean more than after rehab cost or more than it's worth currently if there isn't money being loaned to rehab.