Sorry about the delay. I was away from my computer.
Whether the transfer of the real estate proceeds into the stock trust is _legal_ is a _legal_ question, beyond my expertise, and requiring a detailed study of the trust documents. Exactly what transfers are allowed from an irrevocable trust depend on the trust documents.
It should probably also be pointed out that the trusts and the beneficiary are probably _related_, for the purpose of recognizing gain or loss. If a trust "sells" something to its beneficiary, then capital gains become ordinary, and capital losses are deferred.
However, you may still be able to declare the RE trust the "beneficial owner" of the stocks you put in the stock trust, and issue a nominee 1099 from the stock trust to the RE trust, and putting matters back (for tax purposes) where they probably should have been all along. (This actually is answering a different question than you asked, but it may be the one you should have asked.) You may be able to, in effect, retroactively undo the transfer which you shouldn't have done.
If you (legally, per the trust agreement) distributed the proceeds of the real estate sale to the beneficiary, then much of the gain would also have been transferred, and personal
capital losses could offset the gain. If that's what you mean by "putting his money in some investment account in his name", then yes, that would work.
Capital losses still cannot be transferred to beneficiaries (except as a reduction of taxable income, limited to $3000 total for the trust), until the trust closes. It doesn't matter which trust you're talking about. If the stock trust had capital gains, they would be netted with the capital losses, but any excess still doesn't pass to the beneficiaries.
A quick study doesn't find any justification for combining two trusts for tax purposes, except for combining a trust which became irrovocable with the death of the grantor being combined with the grantor's estate.