Defining a nonlinear capacitor in Ngspice
As you say, the behavioral source in ngspice can only generate a voltage or current as a function of other node voltages or branch currents in your circuit. Nonetheless, you can use this, with some extra elements, to produce a nonlinear capacitor like you seem to need:



Here I used a linear CCCS and a linear capacitor to do the integration of the incoming current and track the charge variable. Then a nonlinear VCVS provides the capacitive behavior of your nonlinear capacitor. The gigohm resistor is there because SPICE requires every node to have a dc path to ground in order to obtain a solution; it will not affect the circuit solution significantly.

There's a similar example, using ngSpice syntax on page 89 in the ngSpice manual here.

Alternate solution

Also, be aware, ngSpice offers a behavioral capacitor model, described on page 71 in the manual I linked. The syntax is

CXXXXXXX n+ n C = ’expression’ &lt;tc1 = value &gt; &lt; tc2 = value &gt;


Here you should understand that the capacitance defined is the differential capacitance 

\$C \equiv \frac{\mathrm{d}Q}{\mathrm{d}V}\$.

To put your equations in an appropriate form you need to re-work them a little bit. You have 

\$V = K Q^2\$.

If you turn this around you have 

\$Q = \sqrt{\frac{V}{K}}\$.

From which you can get

\$ \frac{\mathrm{d}Q}{\mathrm{d}V} = \frac{1}{2\sqrt{KV}}\$

Which you can easily implement in the ngSpice expression syntax.