This is most likely functional constipation, which is very common in 2-year-old children and usually starts after a painful hard stool makes the child start withholding stools out of fear. When stool stays inside longer, it becomes harder and larger, making passage more painful and worsening the cycle. This is not due to a serious disease in most children.
Next Steps
Your child needs regular stool softening for several weeks, not just for a few days. Continue a doctor-prescribed osmotic laxative like lactulose or polyethylene glycol daily until stools become soft and come every day or alternate day. Increase water, fruits, vegetables, and fiber in the diet and avoid excess milk, biscuits, and refined foods. Make her sit on the potty after meals daily to build a routine.
Health Tips
Never stop the syrup as soon as stools pass, as early stopping causes relapse. Do not force or scold the child while she strains. Encourage physical activity and plenty of fluids. See a pediatrician if there is blood in stools, weight loss, vomiting, or if constipation started from birth.