I'm a paediatrician. She is probably constipated as PP says. She can't help it, it's involuntary, she isn't doing it on purpose, it isn't a behavioural problem. Dont punish her or embarrass her for this
Take her to her GP. Increase her water intake, use laxative and/or suppositories to clear the blockage and when current, acute problem is solved, increase fibre.
As a side note, explain to her that it's important to wear clean underwear to keep her skin, her vulva and her bum healthy and comfortable and to prevent unwanted smells. While she is constipated it might be a good idea to carry spare pants everywhere and some wipes for accidents.
This is a really common problem, don't make a deal out of it.
Easy ways to increase fibre in kids diets: weetabix, kiwi, prune juice (initially diluted until they get used to the taste). Food to avoid: bread, pasta, cheese, biscuits.
Suppositories are generally poorly accepted in this age group but osmotic laxatives like Casenlax, work very well and are well accepted and effective for disimpaction and for long term use. Side effects: wind, and increase in leakage initially which is normal and WILL pass. Maintenance during at least six months is recommended to restore bowel tone. Dietary changes are cornerstone of management and should be long term to prevent recurrence.
Good luck, it's very frustrating at first, but it is absolutely a medical condition and not your daughter being naughty. You will get through this, with time and patience and some lifestyle changes.