In this answer, I'm going to use $Q$ instead of $q$ for the capacitor charge.
There is only one certain rule for finding Lagrangians: The Lagrangian is chosen such as to get the correct equations of motion.
Never forget that.
In the case of a circuit problem, the most sure way to know you got the right Lagrangian is to see if it gives you the right equations of motion, i.e. the equations you get from Kirchhoff's laws.
Hamilton's principle
Is Hamilton's principle applicable here?
Let's start out by writing down Kirchhoff's laws for the LC circuit.
Choose the orientation of current so that it's flowing into the inductor as shown.
Then Kirchhoff's current rule and the definition of an inductor says
$$
I = -\dot{Q} \qquad \dot{I} = V/L$$
where $Q$ is the charge on the capacitor and $V$ is the voltage on the capacitor and inductor.
The rule for a capacitor is $CV = Q$, so we can rewrite the second equation as
$$\dot{I} = Q / LC \, .$$
Differentiating the first equation gives
$$ \dot{I} = - \ddot{Q}$$
which plugs into the line above to get
$$\ddot{Q} = - Q/LC \, .$$
Defining $\omega_0^2 = 1/LC$ we now have the usual equation for a harmonic oscillator
$$\ddot{Q} = -\omega_0^2 Q \, . $$
That's the equation of motion for the charge in an LC oscillator.
Now let's see if the Lagrangian proposed by the author gives the same equation if we use the Euler Lagrange equations (a.k.a. Hamilton's principle).
The Lagrangian is
$$
\mathcal{L} = \frac{L \dot{Q}^2}{2} - \frac{Q^2}{2C}$$
so the Euler Lagrange equations are
\begin{align}
\frac{d}{dt} \left(\frac{\partial \mathcal{L}}{\partial \dot{Q}} \right) - \frac{\partial \mathcal{L}}{\partial Q} =& 0 \\
\frac{d}{dt} \left(L \dot{Q} \right) + \frac{Q}{C} =& 0 \\
L \ddot{Q} + \frac{Q}{C} =& = 0 \\
\ddot{Q} = - \frac{Q}{LC} = - \omega_0^2 Q \, .
\end{align}
The result from Hamilton's principle matches the result from Kirchhoff's laws, so yes, Hamilton's principle is applicable here.
Kinetic and potential energy
If yes, why is the kinetic energy part $L \dot{Q}^2 / 2$?
In the strictest sense, the kinetic energy part of the Lagrangian is $L \dot{Q}^2 / 2$ because it works to give the right equations of motion and that's the only thing that really matters in Lagrangian mechanics.
However, another way to look at the Lagrangian of the LC oscillator is to simply note that each term is the energy of the capacitor and inductor respectively.
The energy of a capacitor with charge $Q$ and capacitance $C$ is $Q^2 / 2C$.
The author chose to call that the potential energy.
The energy of an inductor with current $I$ and inductance $L$ is $LI^2/2$.
Using $I = \dot{Q}$ we get that the energy of the inductor is $L\dot{Q}^2/2$, which is what the author used for the kinetic energy.
Therefore, you can reason that the author simply identified the two types of energy in the circuit, called one "kinetic" and the other "potential" and guessed the Lagrangian that way.
More general Lagrangians in the context of circuits
A lot of us first learn about Lagrangians in the context of a physical particle moving around in a potential field.
In that particular case, the Lagrangian is always $\mathcal{L} = T-V$, but that's far from the most general form of a Lagrangian.
What happens, for example, if we have two systems connected to each other, such as two particles connected by a spring or two LC circuits connected through a capacitor?
It turns out there is actually a recipe for finding more complex Lagrangians without just guessing.
That recipe is described for example in this article by Michel Devoret.
The article is a rewrite of a famous set of course notes from the Les Houches summer school(pdf) done to correct a number of errors and clarify some points.
Do not be discouraged by the word "quantum" in the title.
Much of the discussion is purely classical physics.
Inductors also store potential energy temporarily in the magnetic field. Why don't we consider that term?
As just explained, we do, and it's what the author called the "kinetic" energy.