Mithradates - Developing immunity to poison?
Welcome to SE. Edit: The answer is in two parts based on the mechanism of action of the toxin. Courtesy: @David and @jamesqf

Immunity

The white blood cells in the body are responsible for recognizing self or non-self peptides and form the adaptive compartment of the immune system. The B lymphocytes have a receptor that can bind to various peptides. Upon recognition of foreign peptides in the body, they go through a reaction (somatic hypermutation) to become further specific to the foreign peptide. They also differentiate into Plasma cells which can now secret another protein (antibodies) which neutralizes the foreign peptide.

Small amounts, which are non-lethal, but in enough concentration to drive the B cell reaction creates an immunological "memory". This memory allows a faster response to the same peptide compared to the reaction. This in order allows the body to withstand a higher concentration of toxic peptide, which otherwise would have been lethal as its being neutralized.

Vaccines work on a principle very close to this.

Homeostasis

Every toxin interacts which some biological process and drives it out of balance. The body actively tries to restore the balance by some means. 

For example, if a ligand is depleted the body can increase the number of receptors to counter the effect and vice versa.

By ingesting small amounts of toxins body can adjust the equilibrium by very small amount at a time adjusting the concentration of relevant ligands or receptors.

Again, the person who has been through this process can withstand a higher dosage of the toxin compared to a person who hasn't.