Its main meaning today is of purposeless activity, of fooling around, spending time aimlessly or dawdling or dallying.
Many American veterans will remember it, since it is part of the standard repertoire of insults used by NCOs to verbally chastise new recruits — in this case to accuse them of fooling around or wasting time. To American civilians, however, it sometimes has a subsidiary meaning of “to indulge in kisses and caresses”, not a sense much encountered in the military.
It first appeared in the US about the middle of the nineteenth century. A wonderful citation from an Iowan newspaper, the Northern Vindicator, in 1868 suggests that a lovemaking implication was around even in its early days: “The lascivious lolly-gagging lumps of licentiousness who disgrace the common decencies of life by their love-sick fawnings at our public dances”.
Jonathon Green, in his Cassell Dictionary of Slang, suggests it may come from a dialect word lolly, meaning “tongue”. If it is, then it’s a close relative of lollipop, which is also thought to come from the same source. Another spelling of the word is lallygag.