I recently touched on this with specific examples as part of an answer on validating source, and on the line between myth and history. The key components are validation and context.
- Does the text itself make it obvious that you're reading fiction. This isn't always the case because ancient stories often portray themselves as historic, but sometimes it's very clear cut, like a play or a work of satire.
- Does this text agree with other clearly historic texts and archaeological evidence? Absence of evidence is never evidence of absence, but it does make historians question the text. Evidence of absence can also be proven with other sources and physical evidence.
- Do other sources discuss the text in question? If you have another ancient author explicitly discussing the text your wondering about, then you can figure out how ancient people treated it. If they cast doubt or called fictitious, then that's pretty good evidence (though not certainty, archaeology occasionally vindicates ancient authors despite ancient criticism).
- Finally, does it seem possible? If there's elements of mythology, magic, or prophecy, those parts at least can be discounted right away. That doesn't mean there's nothing to be gleaned from those elements about actual history because people certainly believed in those as real phenomena, but it does indicate a fictionalize version of events.