No, it is not illegal. Cheat Engine is a legitimate debugging tool, and editing a single-player game you own on your own machine breaks no law.
Getting banned is another matter entirely. Online games treat memory editing as cheating, and anti-cheat systems are good at spotting it — Club Penguin and its successors will happily lock an account for it. My honest recommendation is to leave it alone in anything with other players in it. If you are determined to experiment anyway, keep it strictly offline, keep it quiet, and accept that a ban is a real possibility. It is a bad idea dressed up as a shortcut.