As you say, there are enough weeks in a year for there to be four 13-episode parts. This is true, and each of these parts is a season. However, there aren't always exactly 13 days of each day of the week in season. For example, the summer 2016 season (July-September) will have 14 Saturdays.
As to why shows go for 12 or 13 episodes, it's generally something the anime production companies decide early on in creating an anime (a few months prior to the show airing). Different studios and shows will have their reasons, but either way, there we are. Unless we were there when the decision was made in some board room, we don't know why a show got 12 episodes over 13.
When the planned season where the show will be airing is about to start, the anime production companies will call the TV stations and ask for time slots. (Generally, TV stations themselves aren't involved in producing anime, only just putting them on TV.) For example, one will call to say "we want to air a show on Saturday nights at 24:30 for the next 12 Saturdays". Another will call asking "we want to air a show on Thursday nights at 24:00 for the next 13 Thursdays". Whether or not they get the slot depends entirely upon whether or not someone else took it yet (and if the price for the slot is worth it).
Anime TV scheduling is competitive, as is a number of things in the anime production world. Anime production companies will try to be as quick as they can about getting a TV slot, but it usually isn't until relatively close to the start of the anime season that TV stations get a full schedule figured out. TV stations can count on their slots being filled, though, with the wide amount of anime coming out each season nowadays (and they can always rely on reruns otherwise).
So, to sum it up, anime production companies know from early on how many episodes they want. How they decide that is dependent upon the show. When it comes to the TV stations, they just offer up the time slots, that's it. The anime companies take them as soon as they can, for as many nights as they want them.