It depends. I think generally historical movies fall into two categories. First, there's the historical movies that just straight up make things up, these generally aren't great for helping people understand history better, often they do the opposite. Best example being Enemy at the Gates which is the source of a lot of misconceptions people have of the Soviet Army such as them sending troops out to fight without guns which is simply not true.
Gods and Generals is another example, being boring and blatant Lost-Cause Confederate propaganda. Or Red Tails, which while I appreciate for shining more light on the Black airmen, has a mountain of historical inaccuracies when it comes to the actual aerial combat that occurred in WW2. Most historical movies fall in line with Red Tails where there's just a lot of historical inaccuracies for whatever reason. Rather than being intentionally malicious like Enemy at the Gates or Gods and Generals. If the movie and story itself is good enough I can overlook the inaccuracies, such as with Inglourious Basterds, which doesn't take itself super duper seriously anyway. But they shouldn't be taken as genuine representations of the time period or as substitutes for properly learning about a specific time period or subject.
I much prefer the second category of more accurate and realistic historical movies, and I do think they help people understand history better. Come and See is a prime example. A Soviet anti-war movie, completely grounded in reality as it showcases just how horrible it was to simply exist around the Eastern front. Downfall was a very accurate portrayal of the final days of Nazi Germany. Oppenheimer was also relatively accurate, it does take some liberties but I was surprised at how well represented everything was overall. Schindler's List, goes without saying. Saving Private Ryan is also quite good especially for how big of a movie it was. Just a few examples, there are a lot of good (and mostly accurate) historical films that are beneficial to those who watch them.
I think the biggest issue for your average viewer is telling the first category apart from the second Which you really can't do unless you research online or have a decent level of knowledge about the subject the movie is about.