Dear suhas.mv ,
This is working as expected.
When you checked "Send response immediately", the assertions after template response assertion won't be executed, ie. the Raise error assertion won't be executed, so your template response will be returned to requestor and gateway will think this policy executed successfully.
When you don't check "Send response immediately", the gateway will continue to execute the remaining assertions until the end of the policy, or an error to terminate the policy. If there are multiple assertions to generate the response, the latest one will be returned to requestor. When Raise error assertion executed, gateway will generate a standard error response and terminate the policy execution. As raise error executed later than template response assertion, the error response will be sent.
If you want to customized the error response, you should use custom error response assertion,
Customize Error Response Assertion - CA API Gateway - 9.2 - CA Technologies Documentation
For more details about raise error assertion and return template response assertion, you may refer to,
Raise Error Assertion - CA API Gateway - 9.2 - CA Technologies Documentation
Return Template Response to Requestor Assertion - CA API Gateway - 9.2 - CA Technologies Documentation
Regards,
Mark