I've tried this with many phone cameras and almost all of them focused well for macros but only for a moment before they defocus to focus something further behind. If the camera can focus on objects such close then why do they do defocus from that distance? Also I haven't compared this with an app with manual focus, the above mentioned issue is with auto-focus.
I have observed the same, I have also observed in the past that it's very hard to accurately judge focus on a live lcd without specific focus aid features like focus peaking or zoom.
My assumption therefore is that the camera's minimum focus distance is enough to make the subject look superficially in focus but not to qualify as a lock for the AF system. Having failed to lock on, it winds out to a longer distance and may achieve focus lock on the background.
If this is the case, then moving a little bit further from the subject should allow a lock to be achieved.