Could citing a database like libgen get one into trouble? Databases like libgen are considered illegal in most countries, I understand. So, if someone acknowledges libgen as the database from which a book has been retrieved on the Reference List, could he/she get into trouble?

This is in cases, where you have to cite the database, apart from the book. Suppose, you cite an e-book or an online article, you have to include the database too in certain referencing systems.
The databases are illegal in that they violate copyright law. The owner of the database is clearly in violation of the law, but users of the database are generally not. That said, I can imagine some authors would be upset to see a published link to a pirated version of their book. Why not just go to the library and confirm that the printed version matches the online version.