I was told that "not on purpose" cannot be used in the middle of a sentence. For example:
"I was walking and, not on purpose, I participated in a marathon".I am aware of the fact that there are more elegant expressions such as unwillingly, unwittingly etc etc but my question is: is the above correct? Am I allowed to use "not on purpose" in such a way?
It's very unnatural. Having said that, it would be unnatural to "accidentally participate in a marathon"! A marathon is usually a running race and the routes are strictly controlled with fences and tape so it would be nigh on impossible to accidentally get caught up in one while you're out for a walk.
Remember - if you don't use correct capitalisation, punctuation and spacing, anything you write will be incorrect.