The discriminating clue is that the only complaint is pain that appears specifically while the child is passing stool, with no vomiting, no bleeding and no obstruction. A symptom tied so tightly to the act of defecation suggests a lesion sitting low in the rectum that gets squeezed and irritated as stool passes.
A juvenile rectal polyp matches this perfectly, as it is the most frequent rectal growth in children and produces exactly this kind of defecation-related discomfort.
The alternatives can be reasoned away. Intussusception is a triad of colicky pain, vomiting and currant-jelly stools with a palpable sausage-shaped mass, so the absence of vomiting and bleeding argues against it. A Meckel diverticulum typically announces itself with painless bleeding per rectum rather than pain on defecation. Necrotising enterocolitis is a sick neonate with distension and bloody stools, not a well child with isolated pain while stooling.
By elimination and by the defecation-linked pattern, the diagnosis is a rectal polyp.
\[\boxed{\text{Rectal polyp}}\]