Yes Security guards can legally detain you until the police arrive on scene and some malls even have jails where they put shoplifters until the police arrive to take over.
You can however prevent detaining from a security guard from running and that's not illegal but then if the police have to chase you down then you could be in more trouble especially if you're arrested for shoplifting.
You shouldn't steal or shoplift but if you do and get caught it's best to not run as it just makes matters worse once they do catch you.
If you're caught on private property by a security guard and you haven't done any criminal damage or theft then the most they will do is hold you and call the police and have you warned of trespassing.