Arithmetic overflow error for data type smallint, value = xxxxx
You mentioned database and server-level settings are the same, but how sure about that are you?  And is it possible something is changing a setting at the session level?

This produces the error for me (of course):

SELECT CAST(40000 AS smallint);


But this does not - it just returns NULL as the value:

SET ARITHABORT OFF;
SET ANSI_WARNINGS OFF;

SELECT CAST(40000 AS smallint);


Check to make sure the session doesn't have these SET options disabled by running this on both machines and seeing if the value is different:

SELECT @@OPTIONS;


You could also check to see if this is set at the server level using sp_configure:

EXEC sp_configure 'user options';




The more likely situation is that, due to having a different execution plan on the different servers, the higher value is being filtered out before being cast.  Solutions to that are covered here (and in the linked duplicates):

CAST throwing error when run in stored procedure but not when run as raw query