If I may assume a little:
Not only can they be in the same box together, you can terminate them together if the smaller (for example, the #14) conductor's ampacity is not exceeded by the overcurrent protection. This would be legal by the NEC.
Case in point: Light fixture has a #14/2c switch leg. At the switch box, there is #12/2c homerun. The #14 white is wirenutted to the #12 white. The #14 black (switchleg) is on one screw(terminal) of the switch and the #12 black (homerun) is on the other screw. At the panel, the #12 black is terminated to a 15 amp breaker.
The install described above is NEC legal, but not widely used for many reasons. Typically, this is only done if #12 is the only wire available, (e.g. because you used up all the #14 on the switchleg)
Two reasons against:
1) #12 is more expensive
2) #12 is typically used for voltage drop and in that case the entire ckt is #12 including the switch leg, so if someone else terminates the panel and sees the #12, they might assume that the entire circuit is #12 and install a 20 amp bkr, which could not protect the #14 switchleg like our above example.
Reason #2 may be why you were told this is illegal. Just a guess.