That depends entirely upon where you are in the world.
For the US though, ignoring state level and circuit court level and merging it all together.
Basic principle is "your device, your rules, your choice of actions", and is the basis for most sites like this*. That however gets modified by many things.
The original ruling that most went off (for a lot of electronics actually) was sega vs accolade (
http://digital-law-online.info/cases/24PQ2D1561.htm ), where accolade worked around Sega's protections and the courts said that is cool. Another with galoob vs Nintendo (
http://www.museumofintellectualproperty.org/features/game_genie.html ) are also worth considering as it covers some things for the game genie and thus game modification (short version is the parent company for game genie asked the court to say yay or nay, a so called declaratory judgement, and they said yay). In these discussions Atari Games Corp. v. Nintendo of America Inc. (
http://digital-law-online.info/cases/24PQ2D1015.htm ) comes up but that is more that Atari obtained the means by some kind of deception or falsehood rather than simply working around it like Accolade.
This was pre DMCA though, most people that look at it consider the DMCA a horrid piece of law but it is a piece of law and thus gets to be discussed. One of the bigger provisions of the DMCA was that bypassing protections, even if they are weak as you like, is not cool. This would then appear to stop a lot of things that might be acceptable under other circumstances, including under the case law mentioned above.
However there are exemptions to the DMCA. More recently there were a bunch added and some of those change things we see and deal with around here
https://library.osu.edu/blogs/copyright/2015/12/30/new-dmca-exemptions/
Some of those however would appear to not cover game consoles as they are presently known, and have typically been known in the US since Nintendo appeared with the NES (there was no crash in Europe, the C64 was doing fine and the amiga was also very much present in all this), by virtue of them being somewhat limited purpose devices.
Some more
https://www.eff.org/issues/dmca-rulemaking
The console makers however would have you think you are the scum of the earth for considering such a thing. This matters little but knowing how your opponent thinks is not necessarily a bad thing. Most find Nintendo's wonderful document on the matter to be good reading
https://www.nintendo.com/corp/legal.jsp . Said position has however been seen to have a bit of a stifling effect on emulation of older NES titles in some instances,
http://www.gdcvault.com/play/1023470/-It-s-Just-Emulation covers some of it in passing.
End User agreements actually mean something in the US (many other places tear them up if they are presented after the point of sale) but not an awful lot as far as this discussion goes, unless you want to consider warranties (gets complex if a ruling like "did the mods cause failure? No, fix it anyway then" comes into play wherever you are at).
Flash carts and mod chips seem to get struck down fairly often within the US, though customs, border protection and the like really don't seem to care -- never heard of an individual getting stung going through customs/immigration (I have personally travelled several times to the US with such things and not heard word one, even got singled out for an extra special talk once**) and it is rare enough that should a shipment of a crate of the things get stopped in customs it tends to make the news around here. Ignoring basic customs stuff then the only times we really ever see them get tooled up and kick down doors is when the would be mod shop is also copying games to the devices at the same time, see also people downloading as much as they like but it is the uploading they care about. That it seems to have to happen for every console coming out says much to me as it has been years since the PS1 and longer since the SNES which also had commercially available copier devices says much to me.
*some will do different things with different things, for instance here we don't tend to see console/device keys shared, save for unique per console things (you want to get banned then that is your problem sort of thing). Other places have no such qualms, even places with far stricter "no piracy discussions" rules. There does not seem to be a good basis for this, though lot of it happened around the time the HD DVD keys were leaked, so for the most part I tend to call it "don't poke the bear", or when being chased by a bear you only have to run faster than your friends. As it does not tend to add much to the discussion and keys are easy to find then nobody seems to mind so much.
**I will note though that it never even occurs to me to think they are in any way wrong. Some members, typically somewhat younger, actually believe they have some kind of illicit device for whatever reason and that might change something somewhere.
Homebrew vs region locking vs copied commercial games can complicate all this further. For the latter there is a reason "backups" is often used as a term as it one of the basis upon which such things are allowed (part 4 of
https://w2.eff.org/IP/eff_fair_use_faq.php for a start), region locking has not been smacked down despite apparently flying in the face of international trade law (a purposeful restriction on global trade) but is generally seen as a legit thing (you might want to look into the no backups PS1 chips that did region locking and homebrew), and homebrew has been covered a bit already but as it usually gets put in the exemptions above, and counts as a good entry for "substantial non infringing uses" (a choice legal phrase in matters like this) when discussing all sorts of things (emulation being a good one) then yeah.
ROM hacking would be another facet in all this but there is precious little legal paper out there on this -- prior to the final fantasy type 0 thing (not sure what basis but more likely competition as they were releasing the same game before too long, not to mention released in a very poor fashion), and pokemon prism (pretty clearly trademark related if you read the docs
https://drive.google.com/file/d/0B0f-_m_8on7BLVhuYnV2a2tuR3M/view ), the only actionable stuff we really had to look at was the 2005 case of tecmo vs various dead or alive volleyball hackers (
https://www.theregister.co.uk/2005/02/10/tecmo_sues_xbox_game_hackers/) which was dropped in short order (
http://www.theregister.co.uk/2005/05/27/tecmo_drops_ninjahacker_suit/ ). There were a few other notices over the years (Chrono Trigger being one of the more notable) but nothing really worth considering -- getting a lawyer to so much as have a chat with you tends to cost about as much as food for the week, if you are lucky, so most just capitulate.
Let's play legal guidelines for various places also issued some things that might pertain to hacking, though again most of it appears to be trademark (apparently endorsed footage of hacked games potentially causing all sorts of troubles and confusion among consumers). Microsoft's being the most overt (
http://www.xbox.com/en-gb/developers/rules ), though Nintendo's were not too far behind (
https://r.ncp.nintendo.net/guide/ ).
You did not mention emulation but I brought it up in passing earlier, here the main case of any merit is the Sony vs Bleem
https://www.law.cornell.edu/copyright/cases/Sony_v_Bleem.htm which most had Bleem on track to win, only to succumb to that old problem of money (if getting a lawyer to speak to you is expensive then getting one to go speak in court is even more so, so much so that "drag a legal case on for long enough until your opponent is bankrupt" is a well documented, and highly effective, legal strategy).