Swansea magistrates said Robert Riley's online messages were also racially and religiously aggravated and that only a custodial sentence could be imposed.
Riley, from Port Talbot, was sentenced to eight weeks in custody after admitting posting an abusive Twitter message about the death of Leeds schoolteacher Ann Maguire.
The 42-year-old was the second person to be charged with the offence in the wake of the death of Mrs Maguire, who was stabbed to death in her classroom at Corpus Christi Catholic College last month.
Yesterday a third person was arrested in Cardiff and bailed.
More top news
Swansea City failed to capitalise on last weekend's dramatic win over Crystal Palace, as they fell to a heavy 5-0 defeat away at Tottenham.
Post Office workers and managers have held a third strike in a long-running dispute over job losses and pensions.
After a cloudy start it will be a dry day today. The cloud will break up this afternoon, with some bright or sunny spells developing