Yes, in many US states, someone under 18 can legally marry with the permission of a judge. And if the applicant is a pregnant 17 year old who wishes to marry her 17 year old boyfriend so their child isn’t “born out of wedlock”, a lot of judges will say “yes”. But if the applicant is a father who says “I think my 12 year old daughter is old enough to get married, and I found her a husband I like”, no way in hell is any American judge approving that, even if the letter of the law says they could.
But in some other countries, there are judges who would be happy to give that marriage official permission.