From a legal perspective, is it okay to customize a plugin’s code?

You should ask your lawyer, never ask legal advice from random people on the net.

Regardless of the legal question, it is rarely a smart idea to fork a plugin unless you understand that from that point forward it is your plugin. You can smartly use GIT to manage synchronizing when the original code updates, but the more changes you make to it, the harder it will become.

This might not be a biggy for a 100 LOC plugin, but will be much harder to maintain if the plugin has 10k LOC. Foe example yoast right now has a new version at least every week, are you really going to merge the code bases every week? that is going to add an overhead to you developent process.

Forking of plugin or theme should be the last thing on your mind regardless if its legal or not.