To add captcha to a form, simply add the captcha field: Assuming your component is com_something
:
<field
name="captcha"
type="captcha"
label="COM_SOMETHING_CAPTCHA_LABEL"
description="COM_SOMETHING_CAPTCHA_DESC"
validate="captcha"
namespace="something"
/>
The validation will handle it transparently for you. Look into com_contact and com_users for examples i.e. components/com_contact/models/forms/contact.xml