Stroke orders of hiragana are ultimately based on the stroke orders of kanji from which they derived. Unfortunately, each kanji has its own history, and it's hard to generalize how the stroke order of each kanji was determined. Similar-looking kanji can have different stroke orders (see this for example), and these are basically something you have to memorize via practicing.
What's worse, the stroke order of a single kanji may be different between 草書 (cursive script, which hiragana are based on) and 楷書 (regular script), and average native speakers of Japanese (including myself) do not know how to write with 草書 today. Only trained calligraphers and researchers understand the essence of 草書.
So it would take you years to truly understand "why". I would recommend you learn hiragana without thinking about the origin too much, just as elementary school kids do in Japan.