I used to do that often with students on an early stage of instruction, both PPL and CPL, so that they could experience the complete lack of outside references you get inside clouds, but obviously taking precautions ( small clouds, radar coverage, good clearance from terrain, no reported traffic, etc...) didn't care much about the legality as i'm talking about a momentarily passage trough cloud, not an IFR navigation...
I allways prefer that they live this potentially dangerous situations and learned from them them with me first, rather than having a surprise flying solo...