The inability to stabilize the intermediate formed after nucleophilic attack makes this reaction impossible in 5-membered heterocycles. However, the presence of deactivating groups attached to the ring can make up for this deficiency, allowing the reaction.
The nitro located in position 5 allows the delocalization of the charge generated during the addition stage.