Reno's right, the trainer and owner decide where to enter.
Every 2-4 weeks depending on the track theres something called a condition book that is published. It's like a menu for the next 2-4 weeks for race conditions (age, sex, number of wins, distance, surface). There are like 13 races listed for each day. The book is written by track management in an effort to write races that will attract a full card for the local horse population (a lot of turf horses stabled here - lots of turf races).
For a stakes race there's nomination about 3 weeks prior (costs $), then you enter again about 5-6 days out (more $). If theres more entries than the track can handle (12-20 depending on the track) the conditions of the stakes or the track management decide who doesn't go (rarely happens)
For a regular non stakes race the process is the same without the nomination part (and sometimes entry is free). More often than not races are cut because there are not enough entrants (that's why they offer 13 and only run 8).