Why is my function returning a different object type?

That might be a bug. You should submit it on AnserHub