Why does it take the very weird loop that it takes in the Pacific Ocean? And also in the Indian ocean too?
The diagram presented in the question is a very simplified version of the meridional overturning circulation. It is overly simplistic and generally creates very large misunderstandings.
A good reference to the evolution of the Meridional Overturning Circulation diagrams is the work by Richardson (2008). Just in case you don't have access to Progress in Oceanography, you can click here and see if that works.
The diagram that I find more useful and, while a simplification, still rather realistic is the one by Schmitz (1996).
Now let's answer the question about the "weird loop". We need to realize that, in the diagram presented, the blue arrows represent flow of deep water (denser water, usually colder), while the red arrows represent surface water flow (lighter water, usually warmer). The loops in the Pacific and Indian ocean represent a transition from cold water into warmer water usually through mixing. The exact location of the mixing and upward vertical flow (upwelling) does not occur in the areas represented by the loop in the diagram, but rather in several other locations in the Pacific and Indian Ocean (for instance, upwelling in the California Current System, mixing in the Indonesian Throughflow).