At first, I had given a value to the password field.
While testing the node I cut-pasted the values from the password text field. So then the value of the text field changed to required: true (I guess because it was under credential) and as I was using the same instance of the node I didn't realise that such a thing could happen.
Got to know about it from reading this:
The required: true is a display feature in the Node-RED editor and is not part of the actual credential value. When a value is pasted into the credential field, Node-RED sets required: true to indicate that a value has been set for the field, even though it is not visible. This is just a visual indication that the field has value and it does not affect the functionality or security of the credential.