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
An east-west split is starting to develop this afternoon. The best of the sunshine in eastern parts, cloudier with a strong breeze in west
Welsh Assembly politicians look certain to net a £10,000 pay rise after the body which sets their wages gave its blessing to the increase.
Appeal for information after eight newborn puppies were found by children playing in a park.