Variable-Gap Capacitors in LTSpice
As per the manual, x is a special variable and for C it's the voltage across the device (so \$i=C\frac{\mathrm{d}v}{\mathrm{d}t}\$, thus \$v\$ is derived), and for L it's the current through it (so \$v=L\frac{\mathrm{d}i}{\mathrm{d}t}\$, thus \$i\$ is derived). But x is not a mandatory variable, that is, just because it's there it doesn't mean you have to use it; it just provides a commodity for notations, in case you use it.
That said, the manual also says:

LTspice will compile this expression and symbolically differentiate it with respect to all the variables, finding the partial derivative's that correspond to capacitances.

Thus having an expression as Q=x*V(ref) means both x and V(ref) will be differentiated. For your case, you have a rational expression w.r.t. the variable, g(t). Then, mathematically, your expression will need to be integrated so that its derivative will give you the variation for the resulting capacitance:
$$\int_x\frac{A\epsilon}{d\pm x}=\pm A\epsilon\log(d\pm x)$$
Let \$x\$ be represented by V(g), which is the voltage that gives the &quot;raw&quot; displacement of the plates. Then, the expression that needs to be used with a behavioiural capacitor is:
Q = A * epsilon * log( d + V(g) )
for d + x, and
Q = -A * epsilon * log( d - V(g) )
for negative d - x. You could also use:
Q = sgn(V(g)) * A * epsilon * log( d + sgn(V(g)) * V(g) )
but you should be careful because sgn() is a discontinuous function, and differentiating that will most probably cause more problems than not. Note that there is no x, and the only time-variable is V(g).
But if this is used in LTspice, it doesn't work as expected:

V1, by generating a unity 1 V/s ramp, will make its derivative 1, leaving the value of the capacitor to be read in Amperes. C1 is supposed to have what I explained above, but the current through it doesn't show the expected graph. That's because V(g) is a sine in itself, which means the formula becomes (\$m\$ being the magnitude of V(g)):
$$\int_t\frac{A\epsilon}{d+m\sin(\omega t)}\mathrm{d}t=\frac{2A\epsilon}{\omega\sqrt{d^2-m^2}}\arctan\left(\frac{\frac{2d\sin(\omega t)}{\cos(\omega t)+1}+2m}{2\sqrt{d^2-m^2}}\right)$$
If you plug in the values, you end up with the expression of C5, which is shown separate of the rest and truncated, since there is a lot of noise in there.
Fortunately, there are alternatives in making a time-variable capacitor, shown in the three boxed versions to the right. All three are plotted against I(Rtest) which is supposed to give the correct variation and, sure enough, they all are the same, but C3 and C4 have numerical issues, while I(B2), the tried-and-tested version sine SPICE itself, is the most reliable here.
The group E1, C2, and B2 form an equivalent variable capacitor. C2 is supposed to have the fixed capacitor's value, but here I omitted d to allow the expression for B2 to be written in a more readable format. The usage is in the very similar manner described in this answer.
Here's the source for the .asc file, copy-paste and save as some_name.asc (be careful to not end up as some_name.asc.txt!):
Version 4
SHEET 1 1776 880
WIRE 480 80 384 80
WIRE 160 96 112 96
WIRE 736 240 656 240
WIRE 816 240 736 240
WIRE 960 240 864 240
WIRE 208 256 112 256
WIRE 288 256 208 256
WIRE 816 256 816 240
FLAG 288 320 0
FLAG 112 336 0
FLAG 112 176 0
FLAG 160 96 g
FLAG 208 256 cap
FLAG 384 160 0
FLAG 736 320 0
FLAG 816 304 0
FLAG 864 320 0
FLAG 960 304 0
FLAG 656 240 cap
FLAG 480 160 0
FLAG 464 496 0
FLAG 464 432 cap
FLAG 608 576 2
FLAG 608 656 0
FLAG 608 416 1
FLAG 608 496 0
FLAG 464 656 0
FLAG 464 592 cap
FLAG -128 800 0
FLAG -128 736 cap
SYMBOL voltage 112 240 R0
WINDOW 0 39 73 Left 2
SYMATTR InstName V1
SYMATTR Value pwl 0 0 1 1
SYMBOL cap 272 256 R0
SYMATTR InstName C1
SYMATTR Value Q=A*epsilon*log(d+V(g))
SYMBOL voltage 112 80 R0
WINDOW 0 39 73 Left 2
SYMATTR InstName V2
SYMATTR Value sin 0 10u 1k
SYMBOL bv 384 64 R0
WINDOW 3 -13 128 Left 2
SYMATTR InstName B1
SYMATTR Value i=-A*epsilon/(d+V(g))
SYMBOL e 864 224 R0
SYMATTR InstName E1
SYMATTR Value 1
SYMBOL cap 944 240 R0
SYMATTR InstName C2
SYMATTR Value {A*epsilon}
SYMBOL bi2 736 320 M180
WINDOW 0 27 -3 Left 2
WINDOW 3 -20 -27 Left 2
SYMATTR InstName B2
SYMATTR Value I=i(c2)/(d+v(g))
SYMBOL res 464 64 R0
SYMATTR InstName Rtest
SYMATTR Value 1
SYMBOL cap 448 432 R0
SYMATTR InstName C3
SYMATTR Value Q=v(1)
SYMBOL bi2 608 576 R0
SYMATTR InstName B3
SYMATTR Value I=A*epsilon/(d+v(g)) Rpar=1g Cpar=1 ic=0
SYMBOL bi2 608 416 R0
SYMATTR InstName B4
SYMATTR Value I=idt(A*epsilon/(d+v(g))) Rpar=1
SYMBOL cap 448 592 R0
SYMATTR InstName C4
SYMATTR Value Q=v(2)
SYMBOL cap -144 736 R0
SYMATTR InstName C5
SYMATTR Value Q=5.752862898435809f*atan(0.1020620726159658*((10*sin(6283.185307179586*time))/(cos(6283.185307179586*time)+1)+2))
TEXT -48 432 Left 2 !.tran 2m
TEXT -48 512 Left 2 !.parma A=0.1m epsilon=8.854p d=50u
TEXT -48 472 Left 2 !.opt plotwinsize=0
TEXT -48 560 Left 2 !.meas i1 find i(c1) at 0.4m\n.meas i2 find i(c1) at 1.2m\n.meas t1 find i(b2) at 0.4m\n.meas t2 find i(b2) at 1.2m\n.meas xx param epsilon
RECTANGLE Normal 1104 368 608 208
RECTANGLE Normal 1040 528 384 384
RECTANGLE Normal 1104 688 384 544
RECTANGLE Normal 560 368 64 208