In fact, this is not mandatory. However, banks generally require or advise customers to sign for two reasons. First, when making large purchases, they can check their identity documents to prevent others from illegally spending. Second, the word "signature" can also protect the safety of your funds. When signing after consumption, the staff can compare it with the signature on your card to distinguish right from wrong.
There are two ways of credit card consumption: signature consumption and password+signature consumption. When the customer only uses the signature, the merchant has the obligation to check the signature to ensure whether it is used by himself.