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
Andrea Byrne presents the first episode of the new series Helimeds which follows the Welsh flying medics.
Variable cloud and clear spells overnight with isolated showers mainly in the north.
Becoming drier and brighter from the northwest during the day, but with the risk of scattered, locally heavy, showers developing later.