Cohen was convicted last year of crimes including tax evasion, lying to Congress and facilitating illegal payments to silence two women, adult film star Stormy Daniels and former Playboy model Karen McDougal, who claimed they had affairs with Trump, the BBC reported.
After his May release, authorities this month said Cohen violated the terms of his release.
Cohen was re-arrested on July 9, - days after he tweeted that he was "close to completion" of his tell-all book relating to the President.
The book reportedly details alleged racist comments made by Trump.
US Judge Alvin Hellerstein issued the ruling during a tele-hearing on Thursday.
He said that Cohen's return to jail was "retaliatory because of his desire to exercise his First Amendment rights to publish a book and to discuss anything about the book or anything else he wants on social media and with others", reports the BBC.