I've owned a couple of those; when I say "this space" I mean top-of-the-line smartphones with great cameras. Those Samsung & Sony phones fulfilled only one of those parameters.
Looking at any sort of comparative review, you'll find that on some shots the Samsung produces better results; on others, an iPhone looks better. Each phone may perform a little differently in different situations -- low light, high contrast, whatever. But taken as a whole, at least some Android flagships' cameras have been as good as the iPhone's for a couple of years now.
Nexus phones have been noticeably worse, but they've also tended to cost 60% as much, so it's not exactly an easy comparison to make.
what do you think of nexus 5x in that regard?
The Nexus 5X's camera also kills the Nexus 5's. Nexus 5's camera was poor.