Molecular mimicry is a mechanism by which an immune response raised against a pathogen cross-reacts with a self-antigen. The trigger is structural similarity: a peptide from the pathogen binds the same MHC molecule and presents a shape similar enough to a self-peptide that the same T cell receptor recognizes both. The lymphocyte is not self-reactive by origin; it was selected against the pathogen, and its cross-reactivity with self is an accident of resemblance.
The sequence matters. First, the pathogen peptide is presented and activates a T cell clone. That clone expands and becomes an effector population. Later, when the same T cell encounters the self-peptide displayed on host tissue, the receptor binds, the cell is already activated, and it attacks the tissue. The same logic applies to antibodies: an antibody generated against a pathogen protein can bind a self-protein with similar surface structure. The response is misdirected, but the effector machinery itself is functioning normally.