The phrase "legally speaking" is a term used to indicate that the speaker's opinion or statement is based on legal principles and precedents, rather than personal beliefs or opinions. It is a way of emphasizing that what follows should be understood in the context of legal matters.