Your forward method looks generally alright, but to make sure output2 (and its corresponding loss) only calculates gradients for the last two linear layers, you would have to detach the input to these layers:
    def forward(self, x):

        # Input size is (25, 2, 14, 14)
        x = self.convlayer1(x)
        x = self.convlayer2(x)
        
        x = x.view(25, 2, -1)
        
        # (25, 2, 3200)
        x = F.relu(self.lin1(x))
        # (25, 2, 10)
        output1 = self.logsoft(x)
        
        # (25, 2, 10)
        x = F.relu(self.lin2(x.detach())) # add detach here!
        
        # (25, 2, 1)
        x = torch.flatten(x, 1)
        
        # (25, 2)
        output2 = torch.sigmoid(self.lin3(x))
        # (25, 1)
        return output1, output2

This will make sure that the backward pass originating from output2 will be stopped at this point and won’t calculate any gradients for the previous layers.