Dad of one Andrew Brennan’s behaviour was “bizarre and peculiar”, Hamilton Sheriff Court was told.
Brennan (44), of Kingfisher Court, Motherwell, admitted touching Chloe McGhee’s hair and punching her repeatedly on a train between Glasgow Central and Uddingston on February 3.
He also admitted spitting on British Transport Police officer Christopher McDade at Hamilton police station after the incident.
The woman he punched did not suffer serious injury.
Defence agent Diarmid Bruce said his client, a self-employed electrician, had mixed medication with excessive drinking.
The lawyer admitted: “This was bizarre and peculiar behaviour which was recorded by CCTV.
“His position is that a man made comments about him and the woman got between them.
“He had kept out of trouble for a long time, but has let himself down on this occasion. He has made an idiot of himself.”
After studying background reports, Sheriff Douglas Brown ordered Brennan to carry out 160 hours of unpaid community work within nine months.