In most cases, downloading music from games or anime without permission does infringe copyright, so it's generally considered illegal. My advice: be cautious about what and how much you download, and favor legal sources whenever you can to stay on the safe side.