I cannot reproduce the error using the DCGAN Discriminator and your set_requires_grad method:
nc = 3
ndf = 4
netD = Discriminator(1)

state_dict = copy.deepcopy(netD.state_dict())

set_requires_grad(netD, True)  # enable backprop for D
netD.load_state_dict(state_dict)
> <All keys matched successfully>

set_requires_grad(netD, False)
netD.load_state_dict(state_dict)
> <All keys matched successfully>