How does the texture know exactly where its supposed to be applied?
Do a google search for "UV mapping."  "UV"s are texture coordinates that Blender or other software uses to know where to apply the texture.  That texture you have happens to coincide with the UV coordinates of the cake.  Try another texture and you'll see it doesn't match at all.  

Here are a few links to get you started:
https://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/UV_Map_Basics
https://en.wikipedia.org/wiki/UV_mapping
https://www.creativebloq.com/features/uv-mapping-for-beginners