The 27-year-old, who scored 10 goals in Serie A for Lazio last season, has signed in time to be available for Tuesday's Premier League clash with Nottingham Forest, West Ham said in a statement.
"I'm really happy because it's a very important challenge for me personally and I've come to contribute, to try to help the team as much as I can,” said Castellanos, who will wear the number 11 shirt at West Ham.
West Ham said their coach, Nuno Espirito Santo, had identified the former Girona and New York City FC player as a key target.
Relegation-threatened West Ham, who are winless in their last nine matches, are 18th in the table, four points below 17th-placed Forest.
“Every match is a battle... I'm going to give everything to defend this jersey, and obviously, to achieve our goals day after day,” Castellanos added.
