To suppose that there are (positive) legal reasons why a formally valid law can be voided for moral impropriety is a logical error. To suppose that all formally valid laws are morally obligatory is a moral error.
John Dunn, ‘Consent in the Political Theory of John Locke’, The Historical Journal, vol. 10, no. 2 (1967), p. 153-182