Cells inside your mouth will slough off from swabbing. Every cell in your body has a full copy of your genome so you are able to sequence it from that.
A mouth swab gets DNA by getting little mouth cells on the swab. They can then use those cells to extract your particular DNA and determine whatever the doctor or scientist is looking for.