Nowadays the sprockets are shaped to help the chain onto neighbouring sprockets (is that the hyperglide bit?) - and I dunno if those would differ between same sized sprockets from two differently ranged cassettes.
But they didn't used to be, so I guess it ought to work fine (perhaps not so well under load, but changing under load is probably best avoided anyway). Might have to be particularly careful - load wise - changing between the two with the big jump.