At one time, cashiers were instructed to look at the signature on the back of the card and see if it resembles the signature on the receipt. However, most cashiers these days are told not to worry about it anymore.
Cashiers are not expected to be handwriting experts. And signatures on electronic signature pads often don’t look much like signatures on paper.
If cashiers decide that the signature doesn’t look enough like the card and reject the sale, they are potentially mistaken and angering a good customer. If they are in doubt, they can and sometimes do ask for additional ID, but a store may decide for business reasons that they would rather deal with the hassle of fraud than with needlessly angering customers, and set policy for cashiers to accept all signatures automatically.
Signatures are sometimes used after the transaction to show that a disputed transaction was either legitimate or fraudulent. (This has happened to me. I went to a restaurant and paid with a card, and a couple of days later someone else used my card number at the same restaurant. The manager found my slip with my signature, and also found the fraudulent slip with a signature that was clearly not mine.)
The signature is not so much a security measure as it is a legal one. When you sign your credit card slip, you are saying, “This is my card, and I authorize my bank to pay the merchant, and I agree to pay my bill.” It is similar to signing a check.