The joke is a pun.  A dentist is a doctor who specializes in teeth.  Dentists would perform a filling on a tooth that had a cavity, or a decayed part of the tooth.  A 'cavity search' is a search usually performed by police or security to check any place on a person that may be hiding restricted items.
The dentist ' s alibi was full of holes , so the police performed a cavity search .