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.