(almost) as wide as the widest unsupported tunnel
First, the flippant answer:
- as big as an elephant if the cave is big enough for an elephant and there is a limited body of water
- as big as a blue whale if the underground lake / sea in the cave is big enough for a whale
If "underground" is taken literally then the size of the cave is the limiting factor.
However, given the reference to the square / cube law in the question, I assume that the OP is actually referring to a deeply burrowing animal, which is quite a different story. I use the term "deeply" because if the animal only digs a hole big enough for it to hide in and covers itself in a centimetre or so of spoil then we're back to an elephant-sized creature, albeit one adapted for digging. I am also not counting giant anteaters or similar creatures that dig into the ground or anthills in order to expose small burrowing prey.
The first critical limit on size is the stability of the ground that the animal is digging in. First, imagine that a human equipped with a shovel but no brains arrives at the foot of a dry sand dune 10 metres high. The human decides to get to the other side of the dune by digging a tunnel through rather than going over or around, despite having no supports for a tunnel. All attempts to dig a man-sized hole in the side of the dune fail as the sand falls in to fill it. Being exceptionally stupid, the digger eventually shortens the shovel handle and tries to crawl forward on hands and knees while digging. Given that the sand is too unstable to hold its shape, the digger has the weight of much of the mass of sand making up the dune above pushing down on their back. Quite apart from the weight crushing him or her, the friction on the digger's back from the sand pushing down makes forward progress impossible. Rule of thumb for a big creature at any significant depth: if the tunnel being dug cannot support itself then the friction will immobilise the creature even if the weight does not crush it.
Second, consider some dry, sandy soil with a rabbit warren dug into it. The soil is stable enough to hold its shape when a hole the size of a rabbit (plus a bit of clearance) is dug, but is too unstable to reliably sustain a human-width tunnel without supports, as overly adventurous children have tragically discovered on various occasions in the past.
Third, consider a person digging into hard clay. Provided they retain a concave ceiling shape (almost as good as a dome), a human-width tunnel can be dug to considerable depths without additional supports, as the clay ceiling and walls of the tunnel have sufficient stability and cohesion to avoid collapse.
Finally, consider a tunnel through stone, ten metres high and wide with a concave ceiling. There are natural formations larger than this hundreds of metres underground, there is no reason why an elephant-sized animal that can dig through stone could not create such tunnels for itself.
This leads to the second limit - what hardness and compressibility of material is it feasible for an animal to dig through? Sandy soil is easy for rabbits to dig through and can be compressed (so not all spoil needs to be removed) but larger animals need not apply. Clay takes considerable effort to dig through and is not especially compressible, so all spoil dug out needs to be removed from the tunnel, but quite large animals can create stable clay tunnels. (Putting the spoil directly behind you as you dig is not a feasible option for a large animal - the dirt you remove always takes up more room than it did before you dug it out. You simply cannot compress it as well as years of sitting in place does.) While there is considerable variation from sandstone to granite, stone is very hard to dig through, not at all compressible and will take up much more room once dug out than it did originally.
The final limit I can think of is related to the benefit in being a burrowing animal compared to the energy cost of tunnelling. Rabbits and similar-sized animals expend relatively little energy burrowing through easily dug soft soil in order to obtain greatly enhanced security from predators. A larger animal will need to expend proportionally far more energy tunnelling through clay or stone in order to... what? Humans tunnel sometimes for minerals/gems and sometimes for protection from artillery fire, but we expend considerable energy doing so and there is no real equivalent for non-sapient animals. The vastly increased energy requirements and tool hardness required to tunnel through stone compared to clay makes stone an infeasible material for a large animal to tunnel through.
In summary, unless there is a significant benefit to be gained by burrowing / tunnelling, a large animal will not engage in this behaviour, as the energy cost is far too high. Instead of tunnelling, the large animals would live near natural caverns. However, if burrowing behaviour is somehow warranted then a digging animal the size of a polar bear could probably burrow into clay and create a stable tunnel that would not collapse. Unfortunately the published papers regarding the stability of unsupported clay tunnels are hidden behind paywalls, so this is a guess based on limited experience digging fortifications.