Black stools that appear after taking certain medications are most likely not caused by the medications themselves, but by the diseases that these medications treat.
For example, the Helicobacter pylori mentioned here, who is one of the most important causes of gastritis and peptic ulcers, and these diseases may cause bleeding in the digestive tract, which in turn causes black stools.