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
The two projects going head-to-head today are: For the Young at Heart and Y Gwndwn.
David and Angela Southwood, from Newport, say they plan to live in a caravan over the border after learning of the decision.
The fog is expected to become quite widespread and locally dense and freezing during the evening