That's right! He explicitly says at one point: "denn es ist ja nur ein Verfahren, wenn ich es als solches anerkenne" (for it is only a trial if I recognise it as such). Shortly afterwards he walks out, but the following week he comes to the same place at the same time without even having been summoned. What happens to him then in the roof space is bizarre and somewhat dreamlike but it's the following chapter, with the scene in the "Rumpelkammer" (junk room), that presents Josef K as definitely slipping into madness because he apparently sees and hears things that the "Diener" (clerks) do not see and hear. Josef K seems to have a problem more with society or some inner demon than with any real oppressive bureaucracy.
Perhaps all great writers don't fully understand what they write: a muse dictates to them or they're channelling their subconscious. But I find it particularly easy to imagine Kafka as an extreme case of that phenomenon.
He had plenty of time to finish and publish "The Trial" but he couldn't do it. I wrote above "the following chapter" but the manuscript (which Kafka wanted to be destroyed rather than published) consists of separate unnumbered parts so we don't know for sure what order they should go in.