Shaun Moth posted abuse about Mikaeel Kular on the social networking site the day before the three-year-old boy's body was found in a wood in Kirkcaldy.
The 45-year-old posted the comments on an anti-racism page as a police search was underway for the boy in January.
Rosdeep Adekoya, 34, was jailed for 11 years in August for her son's death.
Adekoya had originally been charged with murder, but admitted the reduced charge of culpable homicide.
Moth, from Whitehills in Aberdeenshire, pleaded guilty to conducting himself in a disorderly manner, posting grossly offensive comments on Facebook and breaching the peace, aggravated by religious prejudice when he appeared at Aberdeen Sheriff Court on 4 December.
He was sentenced at Aberdeen Sheriff Court.
Sheriff William Summers said Moth had exploited the media attention around the search for Mikaeel in order to "peddle vile abuse".
The sheriff said: "We live in a multi-racial and multi-ethnic society that remains tolerant of others.
"You are entitled to hold whatever views that you want and to hold them strongly.
"But what you said in these posts was at times grotesque.
"Anyone who disseminates this sort of material must recognise that they will be brought to justice.
"This matter is so serious it seems to be that a custodial sentence is the only option."
Three year old Mikaeel, from Edinburgh, was reported missing by his mother on 16 January this year.
Defence agent Stuart Beveridge said his client had "strong views" and that he was abusing alcohol and drugs at the time he made the comments.
Mr Beveridge said: "He accepts that his comments were callous and in the extreme.
"He has been out of work for six years.
"He was drinking heavily and routinely using cocaine.
"He enjoys the process of argument and debate.
"He accepts that he has strong views and went too far on this occasion."

The 24-hour strike, on 1 February, comes as part of a row over conditions.
Members of the RMT and Aslef unions walked out on 4 January this year, the day many returned to work after the Christmas break.
The pay side of the dispute has been accepted, but Aslef previously claimed Arriva was trying to "railroad through" changes to terms and conditions.
A union statement read: "Aslef today announced that, in the light of Arriva Trains Wales' failure to offer a satisfactory resolution to the long and ongoing dispute with its drivers, our members will withdraw their labour for 24 hours."
Arriva said it "regretted" the disruption January's strike caused to more than 1,000 services it runs each day, when people complained of queues for tickets, long delays and overcrowding.
A man who admitted posting offensive comments on Facebook about an Edinburgh boy beaten to death by his mother has been jailed for 12 months.
[NEXT_CONCEPT]
Arriva Trains Wales drivers are set to go on strike for the second time this year, the Aslef union has said.