Robert Riley regarded Twitter as a chance to engage in "social banter" but had "no idea" of the site's "vastness", magistrates in Swansea heard.
Riley's solicitor, Giles Hayes, said his client - a former bus driver who left school aged 15 with no qualifications - lived an insular life.
The court also heard a report from the Probation Service saying that Riley was a full-time carer for a 44-year-old woman.
"Because of this he has very little time for social activity out of the house," it said.
Mr Hayes described the tweet about Leeds teacher Ann Maguire as "a senseless act at a very sensitive time."
Magistrates were told that, since his arrest, Riley has sought help from counsellors over anger management issues.
His legal team admitted while his offensive comments pushed Riley past the custody threshold, the court could still impose a suspended sentence.
Mr Hayes said that would give the defendant the chance and the support to address his behavioural problems.
However, magistrates decided otherwise and Riley - dressed in a black shirt and trousers - was led down to the cells by two female security officers.
He hid his face as he was then led into a custody van and driven to prison.
More top news
Council have until today to say if the plan to merge. Minister Leighton Andrews says joining together will create "significant savings"
Mainly cloudy, with a little patchy, light rain in the southeast this afternoon. Some brighter spells in the west at times.
A largely dry, cloudy and mild night with fog patches mainly confined to higher ground. Blustery along the coast.