During WWI both sides tunneled underneath enemy positions and placed mines to blowup that section of enemy trench however, the effects of the mines seemed to have little effect on ending the stalemate. Why did either side not dig a tunnel that bypassed the enemy defences which could move troops safely behind enemy lines undetected, then once enough troops had been massed they could attack the enemy's rear and possibly launch a frontal assault as well to trap the enemy between the two forces?
Several things to consider.
Firstly the depth of the fronts. In addition to the forward net work of trenches which would generally consist of multiple lines of defence. But even beyond that, possibly several kilometres, there were typically fall back lines and reserve positions. To be truly in the enemy's rear required managing to get past both of those. Digging tunnel of such a length was not impossible by digging one entirely undetected is extremely difficult to say the least.
Secondly I think you under estimate the sheer scale of the conflicts we're talking about here and as such the problem that relying too heavily on tunnels to move troops presents as a choke point for moving men. Both the more tunnels you dig and the wider you dig tunnels the more material and man power you have to invest in to doing so. Wider tunnels in particular will mean it'll take a fair bit longer to do, both increase the amount of soil you have to move without the enemy spotting you doing so (the scale would give you away) and the both increase the chance listening posts will discover you. So any number and width of tunnels that you could reasonably hope to get away with without being discovered is fairly small. That limits the rate you can bring troops through.
Given that we're talking of engagements of hundreds of thousands of men here, particularly earlier on in the attack the troops exiting the tunnels are going to find themselves horrible out numbered and isolated because you just can't get enough bodies through the tunnels. That leaves you very vulnerable to counter attacks, and as the axiom of Field Martial William Slim says, if the enemy is behind you, he is surrounded.
Additionally if the enemy get their artillary and machineguns ranged on the openings before you manage to expand a wide enough perimeter it's a turkey shoot and a close or direct artillary hit could easily collapse the tunnel. And of course it works both ways, while the men are still coming through you can't afford to be sending wounded back or you slow the movement of troops coming through. And if things go wrong the rate at which you can retreat is also restricted. With the narrow choke points slowing the rate you can fall back a failed attack is going to result in a slaughter.