RE: If I have made code changes in Company A's D365FO environment using Visual Studio, is it possible to deploy it in Company B's D365FO environment?
Every company who is using D365FO should "have" LCS. If they have D365 licenses, they can (and should) create LCS project(s).
But, you can deploy deployable packages via LCS, or via command line (to one box environments). You can deploy the same deployable package to any customer's environment. As long as all target environments have same or higher platform version than the build system that you used to create the deployable package.
But since you talk about copying code of one customer to another customer, please make sure that you have the IPR (Intellectual Property Rights) to this code. This depends on your agreement with the customer. If the first customer owns the code, then you of course need their permission to share it to others.
Also remember that if the second customer has ANY other customization or ISV solution in their system, you can't just deploy your package to their system (test/prod). If you do it, you will wipe out all other CUS/ISV code from that system. Instead this new code must be added to the source control of that customer, and built into All-In-One deployable package that contains all custom&ISV code for that customer.