Historically, there are two competing principles at work in figuring out districts:
You want about the same population in each district
This principle was enshrined in US Court law in Baker v. Carr an Wesberry v. Sanders. Malapportionment is inherently unfair.
You want communities of interest not to be divided.
That said, there is something to be said for ensuring that there is a diversity of opinion on matters, too. It is easy enough to be "equal" with numbers in such a way that certain voices completely disappear from the discussion. This is equally bad, and also to be avoided.
In the USA, for example, Vieth v. Jubelirer basically said that a state can have unequal districts, if the state has a good reason - like if it ensures diversity or allows more voices to be heard.
The first principle of gerrymandering, for example, can be algorithmically derived. It is possible, if the population were say, 1000 people, and there were 10 districts, to put exactly 100 people in each district. Grant you, with freedom of movement, that would hold for about 26 minutes, but hey - there is nothing says you couldn't have districts that exactly apportioned, say, the population on the date of Decennial census.
An At-large seat actually does this in some ways - by lumping everybody into the same district, you most accurately represent the will of all the people in the district.
But, what you miss is a community of interest. Imagine, for example, a three-district region consisting of 100 people, 45 of whom are ardent Yellows, 45 of whom are radical Browns, and 10 of whom are Chartruese. (Only the females can actually recognize those people, but I understand it is a color!). Chartrueses realize they will never be in the majority - and so they tend to vote for the proposals that benefit everybody.
Assuming they are geographically evenly divided, it is trivial to create 3 scenarios:
Gerrymander it such that B is the majority in 2 and Y in 1
District 1 - 20 Y, 15 B, 3 C,
District 2 - 20 Y, 15 B, 3 C,
District 3 - 5 Y, 15 B, 4 C
Here, we see that Yellow will almost always will Districts 1 & 2, and B gets 3. In no case do the C voices get heard, and most laws will favor the Ys, since they have more districts than Bs. We pretty much all agree this is unfair - to "crack" the Bs is bad. Alternatively, you could stick all 45 Bs into one district and "pack" them there- same basic effect.
This is truly gerrymandering for political advantage, and is the unfair case.
Put the population is 3 equal districts
Each district could have 15 Y, 15 B, and 3 (or 4) C.
On the surface, this looks fair, right? Except, here's the problem. In every district, the Cs hold all the cards. Any 2 Cs can swing the district for that entire election. As such, 6% of the population determines the outcome. If 6 Cs collude, they can silence every voice but there own. There are dictatorships that aren't this bad!
Make 1 majority district for B & Y, and 1 competitive district
District 1 - 20 Y, 10 B, 3 C,
District 2 - 10 Y, 20 B, 3 C,
District 3 - 15 Y, 15 B, 4 C
Here, you have communities of interests. District 1 will almost always be yellow, District 2 always Brown. This way, the Y & B's voices will remain, but there is still the swing District C. This is arguably the most fair, because all voices are heard, and even the "disenfranchised" packed voters (the Bs in 1, the Ys in 2) have their voices being heard in other districts.
Now, obviously, the world is more complex, but communities still fall into these patterns. Rural voters, for example, share similar values in many ways. And, their voices should, in a fair society, be heard in, possibly even in greater proportion then their numbers suggest. After all, politicians have to expend more energy to visit a rural area than an urban one. If voices were exactly equal, rural voters would be heard less.
Communities of Interest can be geographical (think Virginia's Eastern Shore, Tasmania, Bavaria vs. Lower Saxony in Germany), ideological (think any party), or based on other factors.
Balancing these factors is why humans get involved in the first place.