If company 2 has the same market cap with zero debt as company 1 has with huge amount of debt, then that implicitly means that the market values what company 2 does less. Perhaps they're in a market with lower growth or have a smaller market share or have a product with less upside potential or have huge lawsuit hanging over them.
If company 1 and company 2 did the same thing and had the same profits and sales, but the only difference is that company 1 had a lot more debt, then the market cap of company 2 would almost certainly be higher than the market cap of company 1. In fact you could then use the Enterprise Value formula to work out what the market cap of company 2 'should' be.
Imagine this example. I'm CEO of Company2 and I take out a 1B loan. Enterprise value is still 2B, because 1B debt is cancelled by the 1B I now have in cash. I then waste all the cash on whatever. My company's enterprise value is now 3B, because the debt has increased it without being cancelled by the cash.
Equally if you are able to take on a lot of debt without it lowering your stock price then that means that the market thinks you're going to use that new money in a smart way to grow your companies value and thus your company is more valuable. If the market didn't believe you would use the debt wisely, taking on debt will lower your stock price.
In the real world you effectively cannot change the amount of cash or debt you have without it affecting your market cap in some way, as all three are tied together in complex ways and this model doesn't offer any insight into how changing one value will affect the others or the overall value going forwards. Think of Enterprise Value just as the price tag of a company at any given moment in time.