“If the court knows herself” is a catch-phrase referencing a joke that was popular in mid-19th-century America. The earliest version of the joke that I have been able to find is from 1853:
When a Kentucky judge, some years since, was asked by an attorney, upon some strange ruling, “Is that law, your honour?” he replied, “If the court understand herself, and she think she do, it are.”
C. Gough (1853). The Cruet Stand, volume II, p. 283. Beddington: J. S. Hiron.
Here “the court” is synecdoche for the judge himself, so that his claim is a logical tautology: of course if he understands the law correctly, then his ruling is correct. (The judge calls the court “she” because courts are commonly personified as female, after Justitia, the Roman goddess of justice.)
The people of Kentucky were stereotypically portrayed as backward in learning but self-reliant, so the idea behind the joke seems to be that the Kentucky judge has little knowledge of the law, but he has the smarts to not let this affect the way he runs his court.
The judge’s claim from the joke became a popular catch-phrase or meme. Here are some examples:
Mr. ALDRICH. I rise to a point of order. I understand the Chair to say that the question now is upon the motion of the gentleman from New Jersey. That motion has been voted on and decided here three times to-night, [laughter,] “if the court understand herself, and she think she do.” [Renewed laughter.]
John C. Rives, ed. (1863). Proceedings of the Third Session of the Thirty-Seventh Congress, p. 579. Washington: Congressional Globe.
But as we say, “a miss is as good as a mile,” only that the next time I go to sea I shall take some grub and some water and a compass, and “if the court know herself, as she think she do,” I shall hardly venture in a craft not much bigger than a washing tub.
Thomas Kilby Smith (April 26, 1865). Letter to Elizabeth Smith. In Walter George Smith, ed. (1898). Life and Letters of Thomas Kilby Smith, p. 397. New York: G. P. Putnam’s Sons.
The neighbor, adopting these conclusions, tried to dissuade Jackson from burying his money in any hole in those remote woods; but Jackson replied, in the words of the Western judge: “If this court understand herself, and she think she do, coal is certainly coming out of that mountain,”—and set to work, encouraged only by his father, then a very old man, and his brother, a self-taught, practical geologist, who joined hands with him in the undertaking.
J. T. Trowbridge (1869) ‘A Carpet-Bagger in Pennsylvania’. In The Atlantic Monthly, April 1869, p. 453–454.
“Well, ’spose you paid me ten dollars for takin’ you over there and back, you don’t think I’d be fool enough to know anything about it, do you? Not if the court know herself, and she think she do, as Esquire Dickens always says when he declines a small marriage fee—because it’s too small!”
C. R. Edwards (1870). A Story of Niagara, p. 160. Buffalo: Breed, Lent & Co.
I turns to Mr. Holmes, and says I, “Looky here, my fat friend, I’m a-running this shanty, and if the court knows herself, you’ll take whiskey straight or you’ll go dry.”
Mark Twain (1907). Chapters From my Autobiography, XXV. In The North American Review, number DCXXV (December 1907), p. 483.
So in the passage from In the Midst of Alarms, Yates just means that he thinks he is not going to jail, but he makes it into a joke by using the catch-phrase.