The litmus paper is an acid-base indicator, and the change in color is attributed to the formation of a compound that is dependent on the number of H+ (which predicts the equilibrium shift in Bronsted acid-base reactions).
For example, HA and A- are the compounds in your litmus paper existing in equilibrium (HA is red, and A- is blue)
HA <---------> [H+] + [A-]
Once you put acid, the acid will introduce an excess of H+(since it donates a proton, once it is in a water solution), bringing an excess of H+ and will shift the reaction to the left, producing more HA and turning the color red.
Or if you meant the colour changing pigment, here is the answer.
This pH paper changes color in different pH solutions because of the chemical flavin, which is a pigment present in red cabbage. This molecule, which is an anthocyanin, is soluble in water and changes color in the presence of various types of solutions. In the presence of an acidic solution, it turns red. In the presence of a basic solution, it turns greenish. In the presence of a neutral solution, it turns purple.