I think it becomes illegal if there is lender fraud. The loan has to be disclosed to the lender and that might trigger denial of the larger mortgage.
But what are called hard money loans are done all the time just as are family loans. The agent might be doing a hard money loan which is within the jurisdiction of a real estate license. You just can't hide anything from any federally insured or sourced loan. That is lender fraud and it carries federal prison time sentences.