How to tell whether lone pairs in heterocycles contribute to aromaticity? How can I decide whether lone pair electrons take part in the continuous overlap of electron or not?

For example, the lone pair in pyridine is not a part of the conjugated system, whereas the lone pair in pyrrole is.

I had read that this was due to the lone pair in pyridine being localised in an sp2 orbital, while the lone pair in pyrrole is delocalised.

How do we identify this?
For the most common situations use this rule: a conjugated ring atom needs either a ligand or a localized electron pair to replace a missing ligand.  Any remaining electron pairs are then part of the conjugated pi system.

Thus pyridine needs a localized lone pair on nitrogen to replace a missing ligand, and that leaves only three bonding pairs for the pi system.  Pyrrole has a ligand on nitrogen so the lone pair is conjugated into the pi system along with two carbon-carbon bonds.  Furan has two lone pairs on oxygen but a missing ligand, therefore oxygen contributes one pair to the pi system.