Definition - What does Swear mean?
To swear means to promise that one will tell the truth.
In the context of the law, witnesses who are called to testify on the stand during a trial must swear to tell the truth, the whole truth and nothing but the truth. If they are found to do otherwise, then they can be prosecuted for committing the crime of perjury.
Justipedia explains Swear
It is common for public officials to be "sworn" into office. Typically, when a public official is sworn into office, they must take an oath in which they declare that they will uphold certain standards or perform certain duties. For example, many members of the military must swear to defend the Constitution from enemies, both foreign and domestic.
So, essentially, when someone is "swearing" something officially, they are promising to be truthful about what they are saying in a legally binding manner.