First, ballots have barcodes unique to the individual. When ballots are received by clerks, they are scanned in and poll books are updated to show that the person has voted.
So if someone sent in their mail ballot and it was processed, and then they showed up to vote at a polling place, the poll worker checking them in would be able to see that they had already voted.
Or, if the person votes early at a polling place, then also cast their mail ballot, their mail ballot would not be accepted for counting.
It is illegal to vote more than once. If someone votes in person and by mail, county clerks are required to provide that information to the district attorney or state attorney general for prosecution. And the penalties are pretty harsh:
Any voter who votes more than once or, having voted once, offers to vote again in the state, or, during a federal election, votes in this state and another state, shall be punished by a fine of not more than five thousand dollars or by imprisonment in the county jail for not more than eighteen months, or by both such fine and imprisonment.