Quoted By:
Ash is an alien robot incapable of truly understanding human emotion. He only lets others travel with him so he can research their behavior. Serena isn't actually his childhood friend, that's just a false memory he planted shortly after he arrived. That scene at the end of XYZ was just Ash transferring all the experience he gained in Kalos to the nearest proxy in order to make room for more data. He did this by transforming his head into a laser cannon, which was too disturbing to be shown on-screen.