There was a lot I found wrong with the episode but overall The tactics used here make perfect sense.
A catapult or Trebuchet has a long range but also has a minimum range due to the way it throws its payload into the air. This means that within a certain distance the enemy is safe from attack.
Catapults and trebuchets are also imprecise so once the armies clash firing would need to stop in order to prevent friendly fire.
Now if the catapults has been placed at the base of the wall behind they would have filled the space between the wall and the fire pit but would have not been able to hit the dead at all. This would have then created problems for the defenders, the unsullied defensive formation relies on them being positioned as a solid unit. You see this in the way they retreat the central soldiers fall back as the formation narrows down (this was one of the best looking scenes of the episode). if they are forced to retreat amongst fixed wooden structures such as catapults this creates small groups that can be picked off piece by piece and makes it harder to fight. Also if the artillery is near the wall it can be easily used to climb up the walls.
The only other tactic with artillary is to place it far far behind the battle but that tactic suits open battle not a defensive action where the aim is to protect a fixed position.
The tactic I don’t understand was the use of the dolthraki. I would have held them back out the way and used them once the army of the dead had reached the castle to attack the rear catching the army between the castle walls and themselves. Charging them off on there own looked great but was always a waste of soldiers.!