It's not illegal, it's just not legally binding. Accepting an EULA after purchase is more like "we would like you to comply to these license terms, but if you violate them, we can't do anything"
In a lot of countries only the terms that were accepted during purchasing are legally binding. So if you buy a windows license in a shop without signing a contract, than no additional terms except general copyright laws apply.
With SaaS and online services this got way more complicated though. They can always ask to accept new conditions and stop providing their services if you don't accept them.
> Meaning you can't use the software because that would be copyright infringement?
Using the software is explicitly not copyright infringement. Private modification probably isn't either. Generally you don't need anyone's license to use your private property as you see fit; copyright is an exception but it only applies to a limited set of things.
In a lot of countries only the terms that were accepted during purchasing are legally binding. So if you buy a windows license in a shop without signing a contract, than no additional terms except general copyright laws apply.
With SaaS and online services this got way more complicated though. They can always ask to accept new conditions and stop providing their services if you don't accept them.