"Is it legal" is one of those fractal questions that can be very hard to answer. Does the state of Maryland have a law against it? A
water quality regulation that regulates it? How about the county, or your municipality? Or is here a property association that has an enforceable opinion? A rural water district that operates
wells that tap an aquifer recharged by your
land? And that's even before we get to the Federal questions. I wouldn't expect a relevant federal statute, but in the many many volumes of the code of federal regulations, who knows? Watershed protection or surface water quality special zones are everywhere, under state and federal law or all the way down to municipal level; they sometimes prohibit stuff that is totally OK just on the other side of a contour line through your backyard that you can't even see. And then we get to the "what effect does the presence of the outhouse have on my ability to insure or finance or refinance or sell" and... there's more, but you get the idea. The only answer you can hope to get is that Permies bugaboo, "it depends" or "it's complicated".
I am not trying to make this harder than it needs to be, I just want to illustrate why there likely isn't a simple yes/no answer you can get here at Permies. Maybe you can get some "I had one on the western edge of Bosephus County and never had legal problems" anecdotes, but even then you won't know if maybe just the relevant authorities never noticed. Nothing short of several hours of research by a sharp
local lawyer who has a good topographical map with your property marked on it who also knows his land use and environmental and health/safety stuff pretty well, is going to give you a firm answer.