Mahler was inspired by a satirical etching called "The Hunter's Funeral," in which a dead hunter is carried to the grave accompanied by all the animals which (one presumes) he killed in life.
His idea was to write an ironic funeral march, using an upbeat children's tune everybody would know, but changing the mode from major to minor.
It's the only quotation used in all of Mahler's symphonies.
It's a funeral march - so the minor sonority fits well - Frere Jacques is in a major key - so it's just a parody, of an old folk song that happens to also be a round, as used in the 3rd movement here. Also, it's not exactly as the old song went anyway. He fancied using it, and why shouldn't he? ...