I agree with the answer from @user6726 but would like to expand on a couple of points pertinent to the title question:
Why is equality under the law, the ideal? Shouldn't high ranking
government and military officials be given greater benefit of the
doubt, trust, etc.?
united-states
Governmental Immunity
The law in the U.S., in reality, does just what you think it should in terms of giving government and military officials greater benefit of the doubt and trust although not at a top constitutional level, and instead, less visibly in the deep inner workings of the system.
Civil Liability For Government Officials
Most government officials enforcing the law have governmental immunity a.k.a. sovereign immunity from most kinds of liability except where there is an express exception to that which the government has authorized. Governmental immunity usually provides complete immunity for most intentional acts that are not violations of constitutional rights. Even when there are express exceptions to governmental immunity, there are usually additional procedural hurdles or pro-government procedural rules that people suing the government must overcome that do not apply to private individuals or companies, and there are often limitations on the dollar amount of liability that can be imposed and how a person who successfully wins a lawsuit against the government can collect their judgment.
Actions for violations of constitutional rights are generally available only for intentional violations and not merely negligent ones (the 5th Amendment takings clause is a rare exception).
Some public officials (not necessarily high ranking) such as prosecutors exercising their discretionary prosecutorial functions, judges carrying out their judicial duties, and legislators enacting laws have absolute immunity from criminal and civil liability for violations of civil rights and almost all kinds of state law civil liability, although not from certain criminal offenses related to corruption and abuse of their government positions.
Other government officials enforcing the law have qualified immunity from civil rights liability in cases where the constitutional right allegedly intentionally violated by the government official was not "well-established" at the time that the act was taken in directly controlling case law. The court created doctrine of qualified immunity was expressly justified as a way of giving law enforcement officers the "benefit of the doubt."
Also, while the employer of someone who violates the law and harms someone is usually "vicariously liable" under a doctrine called respondeat superior for their wrongdoing, that principle was not apply to governmental employers whose employees commit civil rights violations. In the case of a governmental employer of someone who violates someone's civil rights, the governmental employer has liability only if it has a written or unwritten policy that authorized the particular violation of civil rights that is the basis of the lawsuit, and in general, while local governments can be sued for civil rights violations, state governments cannot, only state government employees can be sued for money damages for civil rights violations.
Federal government employees can be sued for only some violations of constitutional rights that state and local government employees can be sued for, pursuant to a case called Bivens. But the U.S. Supreme Court case decided late in the term in 2022 further narrowed the scope of that remedy for violations of the constitution by federal government employees.
Criminal Liability For Government Officials
These immunities usually don't exempt government officials from criminal liability, but these kinds of criminal cases can only be brought by the the federal government or the appropriate state or local governments, and in the case of federal employees, only by the federal government in most cases.
The burden of proof in criminal case (beyond a reasonable doubt) and other procedural protections not present in civil cases also apply in criminal prosecutions. And, historically, government prosecutors have been very deferential to government employees in bringing criminal prosecutions.
There is also complete immunity from criminal liability for some kinds of discretionary policy decisions of government officials, such as the President or military generals deciding who to authorize killing in a war or other military actions authorized by law, or legislators deciding to declare war.
Military Personnel
Military personnel are generally immune from both civil and criminal liability for actions taken pursuant to orders from superiors that were lawful or that the personnel reasonably believed to be lawful at that time that they acted pursuant to those orders. They also face quasi-criminal court martial liability for disobeying a lawful order of a military superior.
The Abolition of Aristocratic Privileges
Unlike the ancient feudal system, however, in which high ranking individuals had protections from liability for all acts public and private which were clearly distinguished from each other, in U.S. law, these immunities apply only for the official actions of the government official in question.
A related element of equality under the law concerns a feature of the legal system that was historically present in English common law, but is not present in U.S. civilian law (outside of courts-martial) which is more equality preserving.
In historic English common law nobles had the right to be tried by a jury of their peers in cases where there were jury trials (i.e. by other nobles of comparable rank) rather than a jury drawn from the general public as in the U.S. which does not allow people to have titles of nobility. The U.S. has greater equality under the law in that respect.
Vestiges of the historic English jury of one's peers system, however, remain in the U.S. court-martial system, in which officers can be tried in a court martial proceeding only by officers of comparable rank or higher.
france
Not all countries follow the common law tradition of providing strong protections as a default for government officials, although the end result is often less different than the starting point.
France, in particular (for reasons rooted in the initial French Revolution and disseminated across the world to countries it conquered and to its colonies) is known for a strong commitment to the "rule of law" that subjects everyone including government officials and the government itself to full legal liability except where a specific law provides otherwise, instead of imposing liability only when a specific exception to the general rule of governmental liability applies.
This is because the French Revolution arose from general disgust with the aristocracy and upper classes, and was not merely a revolution of local elites against a particular foreign monarchy (the English King) which was seen as abusing his legitimate power in the American Revolution.
The structure of "public law" dealing with the operations of government and its interactions with members of the public, is very different in civil law countries like France and Germany, than in common law countries, like the U.K. and U.S.
Public law is conceptualized and institutionalized as a very distinct part of the legal system in civil law countries such as France, rather than merely as a special subject matter area of law within the single unified legal system for public law and private law of common law countries.
In the U.S., in particular, the involvement of ordinary judges in public law decision making has the practical effect of making the judiciary much more political and much more politically relevant.
France, and other civil law countries, more generally, also give prosecutors far less discretion to decline to enforce criminal laws than common law countries do.
china
The ideals of 'equality under the law" and "rule of law" are not universal ones although both are widely held in countries with "Western" political and legal systems models on historic European systems.
On the other hand, Western legal systems generally have long adhered to the ideal of "rule of law", that historic far eastern legal systems, like that of China, largely rejected in deep history (around the time of the Roman Empire) in favor of a Confucian normative approach.
The prevailing view in China was that statutes were prone to manipulation by lawyers without the public good at heart, and that it was more important to train moral leaders than to have strict compliance with slippery legal rules. In the Confucian value system, inequality is normative and developed elaborate principles that clarify who is superior to whom and reiterate the theme that inferiors to obey their superiors and that superiors should reciprocate by treating their subordinates well. This legal tradition rejected the notion of equality under the law in favor of a system of reciprocal obligation between superiors and subordinates.
They had rules, of course, imposed by superiors, but the focus was on the morality of the people enforcing the social order, rather than on the justness and perfection of particular ephemeral laws and rules themselves.
The modern application and enforcement of Western laws across East Asia and Southeast Asia, and popular conceptions of what is just and right in legal matters, in both nominally communist one party regimes, and in more Western style political systems like those of Japan and South Korea, are all all heavily influenced by a Confucian philosophical tradition even when this gets no formal acknowledgment in statutory legal authorities.
But, people in Western legal systems are deeply skeptical of the capacity of the system to put moral high officials in place, and are more prone to see the aphorism that "Power corrupts and absolute power corrupts absolutely" than to trust people in positions of power. Even when people in power have substantial protections from legal liability, there is a strong emphasis in Western political theory on ways to check or limit the power of the government and its officials. The modern trend in Western political and legal systems is to weaken protections for high officials and to further limit their decision making authority, rather than to grant them more discretion.
In the Western political and legal tradition, the phrase "rule of man" in contrast to "rule of law" is synonymous with abuses of power and corruption.