SEO has a great many aspects, but technically search is controlled by computers and software which in turn are controlled by algorithms. Those algorithms are designed to find interestiing and relevant content, which is why search enine operators will advise you to create rich and interesting content if you want to be picked up. On a more mechanical level, just how do those algorithms work? Search algrorithms use three basic concepts
Keyword matching (much abused by early pioneers of SEO, who relentlessly stuffed pages full of keywords, until search engine operators started bringing in penalties).
Contextual linking. This key tenet of SEO id often missed my many text. Search engines look at links into pages and the text in that link and around that link. If the text in and around the source link matches the destination then weight is given to the destination page for the matching keywords or prhases.
Random traffic model. More familiar to most as statistical page rank, this measure of a sites populariity is based on the idea of traffic across the internet being completely random. At its simplest if a site has lots of outbound links and very few inbounds it will have less residual traffic than a site with lots of inbound links and very few outbound. It also follows that links from more popular sites carry more traffic.