Models are not permitted to shoot at enemies that are engaged in close combat, for the simple reason that there's too much danger of hitting a friend! Remember that while a fight may look like two separate blocks of troops fighting head-to-head, it's actually a swirling melee where no one stays still long enough to offer a safe shot!
Some war machine weapons, particularly those that use templates, can accidentally hit friends whilst aiming at the enemy. The key word here is 'accidentally' – you cannot purposefully aim a template so that some of your models will be hit. See the War Machines chapter for more details on these weapons.