Aminu Adamu was detained after the first lady filed a complaint, triggering a police investigation, according to court documents seen by AFP and a judicial source who asked to remain anonymous.
According to the court documents, Adamu said he had commented on a photo of the first lady on Twitter. It was not immediately clear whether he had intended to make a joke or accuse her of corruption.
Adamu was arrested at his university in northern Jigawa state on November 18 and transferred to the capital Abuja, five months after his online post about Aisha Buhari, the president's wife.
It is not the first time that a post on Twitter causes uproar among the country's political class -- the platform was even suspended for seven months last year.
"He was arraigned on Tuesday," his lawyer, Chijioke Kingsley Agu, told AFP by phone.
"The charge is criminal defamation against the first lady."
Adamu was remanded into custody at the Suleja prison near Abuja pending a bail application, and the case was adjourned until January 30.
He faces up to two years in prison, according to Nigeria's penal code.
The police did not respond to AFP's requests for comment.
Amnesty International has urged the authorities to release Adamu.
"His family and friends alleged that he was held incommunicado and subjected to severe beating, torture and other forms of ill-treatment," the rights group said.
Allegations of mistreatment against detainees are not uncommon in Africa's most populous country, despite it having had a stable democracy since 1999 after decades of military dictatorships.