Why does the Lorentz transformation have to be a linear transformation? In my textbook, they say the following statements before doing a proof for the Lorentz transformation:

We know that the Galilean transformation $x' =  x - vt$ is incorrect, but what is
  the correct transformation? We require a linear transformation so that each
  event in system $K$ corresponds to one, and only one, event in system $K$.

Why must it be a linear transformation? Wouldn't any one-to-one function work?
 A: That textbook is in general incorrect. (As I recall, right before that text they also give a B.S. reason why $y' = y$ and $z' = z.$ The simplest reason for the latter is to attach a paintbrush to a train at a height of $2 \text{ m}$ and let it paint the walls of the train station as it drives through, then send a train through the opposite direction with the same paintbrush: the principle of relativity requires that neither one be "higher" than the other because it would privilege a frame of reference; they have to both overlap.)
The reason why the transformation must be linear is really basic. We want the normal spatial operations which preserve distance in our everyday 3D world to also preserve distances in the Lorentz-transformed coordinates. If you've got a nonlinearity then your choice of origin turns out to matter significantly in your reckoning of these distances between events, and then translations of those events in one reference frame will not preserve the distances between them in the other.
Why do we really want this? Because translations are how we define an inertial reference frame in the first place! It would be awful for relativity if Alice thought Carol was an inertial reference frame, and Alice thought Bob was inertial too, but Bob thought Carol was not inertial. Yet that's precisely what would happen if Carol is going in the $y$ direction and Bob's coordinates depend on time in a non-linear way; and it's precisely what would happen if Carol were going in the $x$-direction and Bob's coordinates were linear in time but nonlinear in $x$. You can view this also as a violation of the principle of relativity, if you like.
A: Yes. You can use any coordinate system. And then the transformation between two coordinate systems can be rather complex.
In general relativity in fact, there aren't global inertial frames, so you are forced to either use general coordinate systems or else to use frames locally and patch the results together.
The former is often easiest after you've put in all the work, so easier to just use it. The latter is a good way to understand some things. For instance locally there is no gravity, it's just that the inertial frames are accelerating compared to the ones you are used to thinking are inertial. So of you don't know how gravity affects light on the surface of the earth for instance, then just switch to a frame that is freely falling and then light behaves like it does in special relativity and then you can switch that result to another frame buy lathing them together between each small region.
Gravity locally becomes a purely fictional inertial force. Just like in Newtonian mechanics when you have to add forces proportional to mass when you are in an accelerating frame. Similarly in the frame that is freely falling there is no gravitational force. The gravitational force is a fictional inertial force you think exists because you used a frame accelerating compared to the actual inertial frame. There are still real effects from gravity because those inertial frames are only local.
A frame is just a choice of coordinates and corresponding components for vectors and displacements and such. The geometry is another beast. It doesn't depend on your coordinates or your basis or your origin.
Geometry tells you how much a clock ticks happen between two events depending on the oath it took, for instance. And that does not depend on your coordinates.
That said if you pick a coordinate system that has a sense of time coordinate $t$ that labels events and assigns three other coordinates to the event. And if that coordinate system has the amount a clock ticks be equal to $|t_2-t_1|$ when the other three (non-time) coordinates are the same (where $t_i$ is the  time coordinate $t$ assigned to the corresponding event). If you do that and also have a sense of distance associated with the other three coordinates then $c|t_2-t_1|-d(\vec x_1, \vec x_2)$ will have to equal zero if the events are super close (so any motion has to look like a straight line) and separated by the path of light. At least if the distance function is correctly measuring actual distance.
So if you restrict yourself to these coordinate systems you can in fact think of the coordinates themselves as just components of a 4d vector and the geometry as given by a metric on the vector space that assigns zero to events that have the vector from one to the other satisfy $c|t_2-t_1|-d(\vec x_1, \vec x_2)$ and that assigns positive and negative separation to other events via
$$(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2-c^2(t_1-t_2)^2$$
or by $$(t_1-t_2)^2-\frac{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}{c^2}$$ depending one whether you want to measure the separation as a time or as a distance.
Then you can follow up and also consider other coordinate systems that made the same choice, for instance one that moves relative to you.
So you don't have to consider only these coordinate systems (the ones your book considers). But you should consider at least those coordinate systems. And since coordinates are irrelevant to the physics you could also take your space time as a 4d vector space (with basis left unspecified) that has a thing like an inner product or scalar product that is a function that takes two vectors and gives a scalar again just as a function (so also with no basis specified).
