The problem seems to be something related to syntax table usage. If I set the variable parse-sexp-lookup-properties to nil, motion commands work as expected.