The law isn't "child marriage is always legal" but "child marriage is allowed in specific cases with a judges consent" basically. They usually need to be given a reason to make an exception
it's mostly 16-17 year olds getting married to men (sometimes arranged by the family, sometimes a boyfriend who's only a little older). I think in the past a pregnancy would cause it?
the rare younger cases are mostly for the reason you might think, leaning on the parents wanting it. You'd hope the judge would say no but there's religious communities that still support it.
Devils advocate here, but what excuse could there possibly be to allow a 12 year old to get married?