Is it legal for a dental insurance company to deny coverage as a secondary provider?

Yes, it can be and no it may not be. You did not give enough information for a determination.

Usually, the primary carrier pays their maximum, then the secondary carrier pays some or all of the portion of the procedure that is left BUT not more than the claim itself or more than they would have paid if their contract was primary.

Here are some reasons why it could be legitimate to deny your claim. You could have hit the limits of the secondary policy. There could be a provision in the secondary policy that it does not cover the procedure that you had or that says it does not pay anything if it is secondary. The latter is somewhat unusual but worth checking for.

Did you ask the carrier why they denied it? If they do not point to a specific provision in your contract, ask them to. If they do not, your state Insurance Department should have a consumer representative that you can ask for help in determining whether it was legitimate for them to deny coverage.