Yes, it’s completely legal to invest in stocks from Zambia. All trading services in Zambia are regulated by the Bank of Zambia (BOZ).
And you don’t need to worry, as your broker will use your location to restrict access to any markets or stocks that aren’t allowed in Zambia anyway.